我在这里查看了类似的问题,但似乎没有一个对我有用,我的代码不会将文件上传到新目录。它只返回设置错误“无法上传文件” 请帮忙
if ($_FILES["imgfile"]["type"] == "image/jpeg")
{
if ($_FILES["imgfile"]["error"] > 0)
{
echo "Error: " . $_FILES["imgfile"]["error"] . "<br />";
}
else
{
move_uploaded_file($_FILES["imgfile"]["tmp_name"],
"upload/" . $_FILES["imgfile"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["imgfile"]["name"];
echo "<br> File uploaded successfully.";
}
}
else
{
echo "File could not be uploaded.";
}
答案 0 :(得分:1)
确保已将
答案 1 :(得分:0)
首先确保已将enctype属性设置为multipart / form-data, 试试这个,
$name=$_FILES['imgfile']['name'];
$path="upload/".$name;
$type=$_FILES['imgfile']['type'];
$pos=strpos($type,'image');
if($pos===false)
{
//error
}
else
{
move_uploaded_file($_FILES['imgfile']['tmp_name'],$path);
}