-1

I get the error:

Warning: move_uploaded_file(/var/www/html/images/content/1485397694.JPG): failed to open stream: Permission denied in /var/www/html/content/admin.blog.edit.php on line 48

When I try to upload an image.

The /var/www/html/images folder has permission 777, but it still doesn't solve this problem. I searched for hours now but can't get any further.

    $newfilename = round(microtime(true)).'.'.end($temp);
if (file_exists("/var/www/html/images/content/".$newfilename)) {
  $file_exists = 1;
} else {
  if (!move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/html/images/content/".$newfilename)) {
    $upload_failed = 1;
  }
}

This is the ps aux | grep httpd :

root       836  0.0  1.4 628300 28116 ?        Ss   04:02   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1048  0.0  0.5 628564 10216 ?        S    04:02   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1052  0.0  0.7 631208 14260 ?        S    04:02   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1168  0.0  0.7 631392 14592 ?        S    04:02   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1169  0.0  0.4 628436  9780 ?        S    04:02   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1234  0.0  0.4 628436  9780 ?        S    04:13   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1235  0.0  0.6 631360 13428 ?        S    04:13   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1236  0.0  0.6 631208 13544 ?        S    04:13   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1237  0.0  0.6 631180 13996 ?        S    04:13   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1288  0.0  0.4 628436  9780 ?        S    04:17   0:00 /usr/sbin/httpd -DFOREGROUND
apache    1298  0.0  0.4 628300  8812 ?        S    04:20   0:00 /usr/sbin/httpd -DFOREGROUND
root      1303  0.0  0.0 112668   964 pts/1    R+   04:24   0:00 grep --color=auto httpd
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

2 Answers2

1

Just because your /images file might have the correct permissions doesn't necessarily mean that the /images/content file that it looks like you are moving the image to has the correct permissions. Try directly changing the folder you are moving files to, not just the parent older.

0

You're testing

file_exists("/var/www/html/images/content/".$newfilename)

and then trying to move it if the file does not exist. The error is in your conditional logic. The attempt to move,

if (!move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/html/images/content/".$newfilename)) {
    $upload_failed = 1;
}

should be moved to the clause where the files exists.

wogsland
  • 9,106
  • 19
  • 57
  • 93