I have a classifieds website, and when users post a new classified, they may chose to upload images.
My php code takes the chosen image, uploads it to a image folder, and names it accordingly.
The problem here is, I have to set the images folder to 777 in order for this to work.
My question is, what should the permissions be set to? And any ideas why it is not working if not 777?
If you need more input just let me know…
Thanks
UPDATE
I have a user (danny) which has root access…
The folder where images are uploaded to, as well as the “image_upload.php” file which does the magic, are owned by user “danny”. Then I just tried setting them to chmod 764, but when I do that I get a problem.
See, it seems that I HAVE to set r+w+e permissions for the “public” for everything to work.
Can’t figure out why…
Thanks again
Forget Revelations,
777is the true number of the beast 🙂You should almost never need to set permissions that way. Surely your images are being created in the directory under a single user ID like
php.If that’s the case (and it should be), you just need to add that user to the specific group of that directory and allow group write access,
764most likely, though the last digit may change based on other needs.You can probably figure out which user is running by changing the upload script to do:
or whatever the equivalent is in PHP for running a command line tool.
Then check the
/tmp/id.txtfile for the details. You’ll have something like:Once you find that out (
php), work out the group of thatimagesdirectory:That would be
paxgrpfrom the above transcript. Then ensure that thephpuser is added to thepaxgrpgroup. This can usually be done in/etc/groupby changing, for example:into:
then ensure the directory permissions allow group (but not world) writes.
And, based on your update, it doesn’t actually matter who owns your PHP file, just who’s running it, and that may not be
dannyat all.Otherwise, I could remove any file on the hard disk because
rmis owned by root 🙂The quickest way to find that user out for certain is to change that file so that it outputs the
idinformation as I suggested.