问题
I have a problem. Since hours I try to get a upload script working. I also read some other questions on stackoverflow but nothing helped. The webspace allows file_upload and the size of the file is not too large. The directory where to move the downloads exists, too. My html code is:
Upload: <input type="file" name="file">
And my PHP code is:
if ($_FILES['file']['error'] == 0) {
$tmp_name = $_FILES["file"]["tmp_name"];
$name_file = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "upload/" . $name_file);
}
I echoed $_FILES and the file was in there and there was no error. Everytime I try to upload the file (I also tried to upload other files and file types) move_uploaded_file returned false.
EDIT: The folder is writeable now.
回答1:
Okay, I solved my problem. I enabled error_resporting()
and because any reason the permissions weren't set. Now they are 777 and I can move the files.
回答2:
Folder upload will not writable by others by setting permission 755. You may set permission atleast 666 through chmod command or better set ownership for upload folder for apache user.
I setup it On Ubuntu like that
sudo chown www-data:www-data upload
回答3:
Set the folder permissions on upload
to 666
. This should ensure that the directory is correctly writeable.
回答4:
Hope this may help someone.
I met the same problem, my $_FILES['file']['tmp_name']
has proper returns while move_uploaded_file($_FILES['file']['tmp_name'],$destination_dir)
returns nothing. So I ran this check:
if(!is_writable($destination_dir)){ echo "error in dir"; }
and got the message "error in dir". Even my $destination_dir
in move_uploaded_file
has been set to 777. After spending a long time searching, I found this answer. So these two commands solved my problem:
sudo chmod -R 777 Ad_images/
sudo chcon -R -t httpd_sys_rw_content_t Ad_images/
Now the is_writable($destination_dir)
returns 1 and the uploading is successful.
TL;DR: Make sure your destination directory is writable for php.
来源:https://stackoverflow.com/questions/15722153/files-is-not-empty-but-move-uploaded-file-returns-false