以下是我的代码:
<?php
$name = $_FILES["file"]["name"];
$temp = $_FILES["file"]["temp"];
if(isset($name))
{
if(!empty($name))
{
$location= "upload/";
if(move_uploaded_file($temp, $location.$name))
{
echo "Uploaded!!!";
}
else
{
echo "Error:";
}
}
else
{
echo "Please choose a file to upload";
}
}
?>
<form action= "upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" ><br><br>
<input type="Submit" value="Submit" >
</form>
每当我运行此代码时,我都会收到以下错误,请提供帮助。我是PHP新手,需要尽快学习。提前谢谢。
注意:未定义的索引:第3行的C:\ xampp \ htdocs \ testfolder \ upload.php中的temp。
答案 0 :(得分:3)
$temp = $_FILES["file"]["temp"];
应为$temp = $_FILES["file"]["tmp_name"];
答案 1 :(得分:0)
是$ _FILES [“file”] [“tmp_name”];
提示: 执行$ _FILES变量的var_dump以查看它包含的内容。 后续代码var_dump($ _ FILES); 这会给你答案。
答案 2 :(得分:0)
您应该检查是否在尝试将它们拉出阵列之前设置了值。与使用tmp_name
代替temp
mpaepper一样。
<?php
if(
isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])
&& isset($_FILES["file"]["tmp_name"]) && !empty($_FILES["file"]["tmp_name"])
) {
$name = $_FILES["file"]["name"];
$temp = $_FILES["file"]["tmp_name"];
$location= "upload/";
if(move_uploaded_file($temp, $location.$name)) {
echo "Uploaded!!!";
} else {
echo "Error:";
}
} else {
echo "Please choose a file to upload";
}
?>
<form action= "upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" ><br><br>
<input type="Submit" value="Submit" >
</form>