PHP move_uploaded_file() error?

Viewed 172664

I using following code and it is successfully uploading files on my local machine. It is showing "Successfully uploaded" on my local machine.

// Upload file
$moved = move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . "myFile.txt" );

if( $moved ) {
  echo "Successfully uploaded";         
} else {
  echo "Not uploaded";
}

But when I used this code on my online server then it is not uploading file and just showing message "Not uploaded".

How can I know that what is the problem and how can I get the actual problem to display to the user ?

13 Answers

In php.ini search for upload_max_filesize and post_max_size. I had the same problem and the solution was to change these values to a value greater than the file size.

On virtual hosting check your disk quota.

if quota exceed, move_uploaded_file return error.

PS : I've been looking for this for a long time :)

I ran into a very obscure and annoying cause of error 6. After goofing around with some NFS mounted volumes, uploads started failing. Problem resolved by restarting services

systemctl restart php-fpm.service
systemctl restart httpd.service
Related