试图移动上传的文件,但它无法正常工作

时间:2014-06-01 17:33:25

标签: php file-upload

我正在尝试移动上传文件,但它无法正常工作请告诉我有什么问题? move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

以下是两个警告

Warning: move_uploaded_file(upload/DSCN87279.JPG): failed to open stream: No such file or directory in C:\xampp\htdocs\prcticsephp\upload2.php on line 26

这是第二个警告

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpA1AD.tmp' to 'upload/DSCN87279.JPG' in C:\xampp\htdocs\prcticsephp\upload2.php on line 26 Stored in: upload/DSCN87279.JPG

浏览器向我显示这两个警告,此代码也不会将文件移动到uplod文件夹

1 个答案:

答案 0 :(得分:0)

尝试

$file=$_FILES['image']['tmp_name'];
$image_name= $_FILES['image']['name'];
move_uploaded_file($file,"photos/".time().$image_name); //use time to make sure that the image name is not repeated also the photos is a directory located in the root directory