move_uploaded_file failure

Viewed 27475

Can someone help me understand why this is returning false?

if ((move_uploaded_file($_FILES[$field]['tmp_name'], $path))) {

As in, potential causes. I have checked the variables are correct and I have checked permissions on the destination folder which is 777.

Cheers!

For those wanting to see var_dump ($_FILES);

array(1) { ["image"]=>  array(5) { ["name"]=>  string(14) "accountile.png" 
["type"]=>  string(9) "image/png" ["tmp_name"]=>  string(14) "/tmp/php28IQhv" 
["error"]=>  int(0) ["size"]=>  int(394) } }
10 Answers

Did you edit your php.ini to make sure upload_tmp_dir points to a temporary directory?

Check:

enctype="multipart/form-data"

Inside the form itself, without it file upload won't work at all.

I was facing the same problem.

If your error says "Failed to open stream: Permission Denied" it means the PHP Server is not being capable of creating the new file inside your destination directory.

Once you have set the Linux permissions on the directory (wich sounds like you did by making it 777) you should give that special permission to the PHP Server.

If your folder is named "uploads", you should cd to the previous directory and use the next command:

chcon -R -t httpd_sys_rw_content_t uploads

That definetly solved my problem.

Hope it helps.

Related