PHP警告:move_uploaded_file()无法移动 [英] PHP Warning: move_uploaded_file() unable to move
问题描述
这是PHP代码:
//文件在哪里将被放置
$ target_path =/ var / www / media2net / uploads / uploads;
/ *将原始文件名添加到我们的目标路径。
结果是uploads / filename.extension* /
$ target_path = $ target_path。基名($ _ FILES [ UploadedFile的] [名称]);
if(move_uploaded_file($ _ FILES ['uploadfile'] ['tmp_name'],$ target_path)){
echo该文件。 basename($ _FILES ['uploadedfile'] ['name'])。
已上传;
chmod(uploads /。basename($ _ FILES ['uploadedfile'] ['name']),755);
} else {
echo上传文件时出错,请再试一次!
echofilename:。 basename($ _FILES ['uploadedfile'] ['name']);
echotarget_path:。$ target_path;
}
我已经从客户端检查线鲨知道http发送了正确地,我也确保我正在写文件的目录具有正确的权限,并且php安全模式被设置为关闭。
apache2 error.log文件的输出读取
[Wed Dec 05 09:25:36 2012] [error] [client 74.14.162.250] PHP警告:
move_uploaded_file():无法将'/ tmp / phpVLOnn3'移动到
'/ var / www / media2net /uploads/downloaded_file.png'
在/var/www/media2net/upload.php第9行
任何帮助这个问题或进一步的方法来解决这个问题将不胜感激。
更改/ var / www / media2net / uploads /通过更改所有者chown或chmod
示例
$ sudo chown apache:apache / var / www / media2net / uploads /
$ sudo chmod 755 / var / www / media2net / uploads /
另外,如果 downloaded_file.png
已经存在于该目录中,另一个用户,那么您也需要更改该文件的所有权。
$ sudo chown apache:apache /var/www/media2net/uploads/downloaded_file.png
这样,它可以被Apache成功覆盖。
I've been slowly learning PHP and have found an array of information on the subject and solutions posted by other developers. I am attempting to have an android application upload a file to PHP server via HTTP post. However something is not working on my server side wile attempting to write to file in PHP.
Here is the PHP code:
// Where the file is going to be placed
$target_path = "/var/www/media2net/uploads/uploads";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']) .
" has been uploaded";
chmod("uploads/" . basename($_FILES['uploadedfile']['name']), 755);
} else {
echo "There was an error uploading the file, please try again!";
echo "filename: " . basename( $_FILES['uploadedfile']['name']);
echo " target_path: " .$target_path;
}
I already know from inspecting wire shark on client side that http post is sent out correctly, also I have ensured that the directory I'm writing the file to has the correct permissions, and php safe mode is set to off.
the output from apache2 error.log file reads
[Wed Dec 05 09:25:36 2012] [error] [client 74.14.162.250] PHP Warning:
move_uploaded_file(): Unable to move '/tmp/phpVLOnn3' to
'/var/www/media2net/uploads/downloaded_file.png'
in /var/www/media2net/upload.php on line 9
Any help with this problem or further ways to trouble shoot this would be appreciated.
Change upload permissions for /var/www/media2net/uploads/ either by changing owner with "chown" or by "chmod"
Examples
$ sudo chown apache:apache /var/www/media2net/uploads/
$ sudo chmod 755 /var/www/media2net/uploads/
Also, if downloaded_file.png
already exists in that directory and it's owned by another user, then you would need to change ownership on that file as well.
$ sudo chown apache:apache /var/www/media2net/uploads/downloaded_file.png
This way, it can be successfully overwritten by Apache.
这篇关于PHP警告:move_uploaded_file()无法移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!