4
votes

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 ?

2
Is the file PNGWallpaper.png already present in the uploads directory?Tim
No, the file not present yet, and I am going to upload this.kn3l
I though that the webserver has no permissions to reupload the file to this directory. Probably you have a typo in the path?Tim
Could you tell me more details please .? Thankskn3l

2 Answers

3
votes

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.

0
votes

I had the same issue.

My solution: make sure the destination folder have the "x" permission( 700 ), not only the write permission.