1

my PHP script is using to register new user with his photo.

On Debian, everything was fine, but when I installed on my server RHEL, problems has begun.

Directory /tmp/ rights are 777 and "upload/" has 777 with chown apache:apache.

below is fragment of httpd's error_log:

[Wed Jun 07 15:25:29.363766 2017] [:error] [pid 22867] [client 10.31.242.73:49624] PHP Warning: move_uploaded_file(upload/1268_org.jpg): failed to open stream: Permission denied in /var/www/html/inc/classes/user.inc.php on line 76, referer: http://10.31.242.72/index2.php?mnu=10041

[Wed Jun 07 15:25:29.363808 2017] [:error] [pid 22867] [client 10.31.242.73:49624] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpmY6k8j' to 'upload/1268_org.jpg' in /var/www/html/inc/classes/user.inc.php on line 76, referer: http://10.31.242.72/index2.php?mnu=10041

I don't have any idea, what's wrong with it. Maybe I skipped something?

2 Answers 2

1

I found solution on this website It was SELinux's blame. I just added httpd_sys_rw_content_t to upload directory by typing: semanage fcontext -a httpd_sys_rw_content_t "/var/www/html/upload(/.*)?".

0

Did you chdir() before moving the file? If you didn't, the file is going to me moved to 'upload/1268_org.jpg', but relative to /var/www/html/inc/classes, which result in moving to /var/www/html/inc/classes/upload/1268_org.jpg, and is definitely not your intended location.

Solution: chdir before moving, or use absolute path.

1
  • Unfortunately it isn't a problem :< getcwd() function shows directory /var/www/html/. Even after changing to absolute path, problem is this same :<
    – KalikDev
    Commented Jun 8, 2017 at 7:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .