欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-20 16:47:26
...
本人菜鸟刚学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 目录不存在

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

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