开发者

PHP/Apache: Permission settings for uploaded JPEG image files not correct

I just setup a LAMP development server and am still trouble-shooting some things. The server is installed on one computer and I use a Windows laptop to write my code and test the site via the web browser.

My file uploading script works in that JPEG image files are successfully uploaded to the server, but when I try to view the images in the web browser, permission is denied.

I check the permissions on the file via the server and they are 600. I can fix the issue by chmod 777 theimage.jpg, but this doesn't seem like a good solution at all.

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

Thank-you, Mike

Update

To clarify, I am able to upload a JPEG file to /var/www/test/images, but am unable to view the image in the web browser after it has been uploaded. My script works on the production server (I am using Dreamhost). This leads me to believe that the issue is with the development server that I have just setup. Any feedback is greatly appreciated, even if it is ju开发者_运维技巧st resources that I should read for better understanding the server setup.


You need to change the permissions on the folder containing the file, not just the file itself. Use sudo chmod and sudo chown on the directory that contains the file you want to access, then check to make sure the permissions where changed with the ls -rl command. The permissions used with chmod should be r and w and the directory should read -rw-r--r-- when the ls -rl command is used if the permissions have been changed correctly. Also, if you are still unclear about the specifics of how chmod and chown work check out this link and this link.

EDIT:

Type this:

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

Or this:

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

... to do what you want to do. For more explanation see my latest comment entry below.


I'd say you probably are running PHP under a different uid than Apache. You can:

  • Configure apache/PHP so that they run under the same uid
  • Upon file upload, use PHP tochange the permissions with the chmod function or change the umask associated with the PHP process so that the file gets the correct permissions in the first place
  • Access the images through PHP (readfile) -- not recommended for performance issues
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜