Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chmod, php and imageupload

How should I handle image uploading using PHP?

How should I handle the chmod settings?

Example;

I have a dir called /image/ where i want to upload all my images.

Should I set this dir to chmod 777 and leave it like that? Or should i change chmod on that folder via PHP each time I need to upload a image. Is this correct, or should I be doing something else?

like image 504
jamietelin Avatar asked Feb 26 '10 09:02

jamietelin


2 Answers

As thephpdeveloper mentioned, setting chmod once is enough. All subsequent writes into that directory will not change the directory permissions unless you explicitly chmod it to another permissions somewhere else.

The recommended permissions for directories on a *nix server is 755. Setting permissions to 777 is not recommended. As mentioned by wic, it gives full permissions to everyone that have access to your server. Which makes it vulnerable if you are on shared hosting or sharing the server with other users.

Also to note is how PHP is run on your server. In fact, if you are running PHP as cgi, example suphp, permissions of 777 for directories are not allowed. Having 777 permissions on the directories your scripts reside in will not run and will instead cause a "500 internal server error" when attempting to execute them.

like image 196
girlygeek Avatar answered Nov 02 '22 05:11

girlygeek


I recomend chmoding to 755

like image 2
DCC Avatar answered Nov 02 '22 03:11

DCC