Search code examples
phpapachefile-uploaduploadfedora

move_uploaded_file(): Unable to move '/tmp/phpiS3dQA' to '/var/www/html/mysite/uploads/PNGWallpaper.png


I am using Fedora 16, PHP5.x and Apach2.x

$target_path = "/var/www/html/mysite/uploads/";
$target_path = $target_path . basename( $_FILES['photo_video']['name']); 
if(move_uploaded_file($_FILES['photo_video']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['photo_video']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

When I try to upload I always got the message :

Warning: move_uploaded_file(/var/www/html/mysite/uploads/PNGWallpaper.png): failed to open stream: Permission denied in /var/www/html/mysite/modules/content/cj_c.php on line 44 Call Stack: 0.0002 132524 1. {main}() /var/www/html/mysite/index.php:0 0.0016 153684 2. include_once('/var/www/html/mysite/modules/content/cj_c.php') /var/www/html/mysite/index.php:36 0.0022 160500 3. move_uploaded_file() /var/www/html/mysite/modules/content/cj_c.php:44 Warning: move_uploaded_file(): Unable to move '/tmp/phpiS3dQA' to '/var/www/html/mysite/uploads/PNGWallpaper.png' in /var/www/html/mysite/modules/content/cj_c.php on line 44 Call Stack: 0.0002 132524 1. {main}() /var/www/html/mysite/index.php:0 0.0016 153684 2. include_once('/var/www/html/mysite/modules/content/cj_c.php') /var/www/html/mysite/index.php:36 0.0022 160500 3. move_uploaded_file() /var/www/html/mysite/modules/content/cj_c.php:44 There was an error uploading the file, please try again!

File or folder permission:

drwxrwxrwx. 465 root root 36864 Apr  6 23:20 tmp
drwxrwxrwx. 2 knel knel 4096 Apr  6 22:47 uploads

php.ini

file_uploads = On
max_file_uploads = 20

check what user php is running as

php> echo exec('whoami');
knel

Who can suggestion me the solution ?


Solution

  • Permission denied means that the user under which PHP is running doesn't have a write permission to one of the directories in your destination path (/var/www/html/mysite/uploads/)

    You can use this tool to check permissions on the full path down to the target directory.