当前位置:Gxlcms > PHP教程 > php上传文件提示找不到路径

php上传文件提示找不到路径

时间:2021-07-01 10:21:17 帮助过:47人阅读

本人菜鸟刚学php 想写一个上传图片的程序

$myPicture=$_FILES['myPicture'];
print_r($myPicture);
$error=$myPicture['error'];
echo "error:
";
switch($error){
case 0://这里需要把临时文件移动到指定位置
$myPictureName=$myPicture['name'];
var_dump($myPictureName);
echo "
";
$tmp_name=$myPicture['tmp_name'];
$destination="uploads/".$myPictureName;
echo $destination;
move_uploaded_file($tmp_name,$destination);
echo "文件上传成功";
break;
case 1:
echo "1号错误";
break;
case 2:
echo "2号错误";
break;
case 3:
echo "3号错误";
break;
case 4:
echo "4号错误";
break;
default:
echo "失败";

下面是错误提示:
Warning: move_uploaded_file(uploads/xx.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Apache\test\register1.php on line 31

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\php25F.tmp' to 'uploads/xx.jpg' in D:\Apache\test\register1.php on line 31


回复讨论(解决方案)

move_uploaded_file() 的两个参数出错
$destination写成绝对路径试试

$destination="uploads/".$myPictureName;
改?
$destination=dirname(__FILE__)."/uploads/".$myPictureName;

??

D:\Apache\test\'uploads 目录不存在

谢谢各位大大 还是因为没创建路径 不过一楼和二楼的我也试了 都行 谢谢

???怎么回事 我结贴给分 怎么没给成啊

人气教程排行