How to debug move_uploaded_file() in PHP
Solution 1
Maybe this will work:
if(!move_uploaded_file($_FILES['attachement']['tmp_name'], $uploadfile)) {
echo 'Your file was not uploaded please try again
here are your debug informations:
'.print_r($_FILES);
} else {
echo 'image succesfully uploaded!';
}
Solution 2
Check your error reporting level (see error_reporting
function). You should get a warning or notice that's a bit more descriptive.
Also, check that the user your PHP script runs as (usually the server's user, which is nobody
or www-data
on a lot of systems, but YMMV) owns the directory. With 755
, only the owner of the directory can write to it.
Raphael Caixeta
Web & iOS Developer. @gripd co-founder. #crossfitter. Adrenaline rush junkie. Brazilian. All around nerd, overall awesome.
Updated on June 05, 2022Comments
-
Raphael Caixeta almost 2 years
move_uploaded_file() won't work for me anymore, it was working fine and just stopped out of nowhere. Is there a way for me to check why it's not working anymore? Here's what I currently have, but it only returns TRUE or FALSE.
$status = move_uploaded_file($tempFile, $targetFile); if($status) { echo 'its good'; } else { echo 'it failed'; }
I know the path is 100% correct and the directory is CHMOD 755. Is there anything I might be doing wrong?
-
tmighty over 2 yearsYou should format your code nicely so that it's easy to read. Also, this makes it more difficult to make errors.