我有以下代码
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
我的页面位于http://local.host/nausal/upload.php
现在我遇到了以下错误,虽然我在网站上创建了一个名为upload的文件夹。
注意:未定义的索引:在第15行的C:\ wamp \ www \ Nausal \ upload.php上传
注意:未定义的索引:在第17行的C:\ wamp \ www \ Nausal \ upload.php上传 抱歉,上传文件时出现问题。
答案 0 :(得分:1)
如果表单也是upload.php的一部分,则需要封装PHP代码并首先检查$ _FILES是否为空,否则如果您只想显示表单,则总会收到通知。 / p>
<?php
if(!empty($_FILES))
{
//your PHP-code here
}
?>
<!-- your form here -->
答案 1 :(得分:0)
创建一个名为upload的文件夹 你创建了upload.php
将echo "The file ". basename(
$_FILES['uploadedfile']['name']). "
has been uploaded";
更改为echo "The
file ". basename(
$_FILES['uploaded']['name']). " has
been uploaded";
这将成功上传文件。第一次上传upload.php时,没有选择文件,因此您会看到一些错误。但是在选择文件并单击上载后,您将看不到任何错误。为了避免这种错误,请按照Molle博士的建议进行。