PHP / Apache: resolution settings for uploaded JPEG image files do not match

I just installed the LAMP development server and I'm still worried about some things. The server is installed on one computer, and I use a laptop for Windows to write my code and test the site through a web browser.

Uploading my script file works in that the JPEG image files are successfully uploaded to the server, but when I try to view the images in a web browser, the permission is rejected.

I check file permissions through the server and they are 600 . I can fix the problem with chmod 777 theimage.jpg , but that doesn't seem like a good solution.

Does the solution have anything to do with Apache configuration? Or is there something else I should do.

Thank you Mike

Update

To clarify, I can upload the JPEG file to /var/www/test/images , but could not view the image in a web browser after it was downloaded. My script runs on a production server (I use Dreamhost). This makes me think that the problem is with the development server that I just installed. Any feedback is greatly appreciated, even if these are just resources that I have to read for a better understanding of server settings.

+4
source share
2 answers

You need to change the permissions of the folder containing the file, not just the file itself. Use sudo chmod and sudo chown in the directory that contains the file you want to access, then check if changes are allowed with the ls -rl . The permissions used with chmod must be r and w , and the directory should read -rw-r--r-- when using the ls -rl if permissions were changed correctly. Also, if you are still unclear about the features of chmod and chown, this link and this link .

EDIT:

Enter this:

sudo chmod -R 666 /var/www/test/images

Or that:

sudo chmod a=rw /var/www/test/images

... do what you want to do. For more details see my last comment entry below.

+1
source

I would say that you are probably using PHP under a different uid than Apache. You can:

  • Configure apache / PHP to run under the same uid
  • When uploading a file, use PHP to change permissions using the chmod function or change the umask associated with the PHP process so that the file gets the correct permissions first
  • Access to images via PHP ( readfile ) - not recommended for performance problems.
+1
source

Source: https://habr.com/ru/post/1309926/


All Articles