开发者

Chmod, php and imageupload

开发者 https://www.devze.com 2022-12-21 13:40 出处:网络
How should I handle image uplo开发者_开发知识库ading using PHP? How should I handle the chmod settings?

How should I handle image uplo开发者_开发知识库ading 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?


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.


I recomend chmoding to 755


Only the user running the web server dameon needs permissions to the directory for writing. And you certainly don't want execute permissions on a directory users are uploading to.


Usually, folder settings are set once and that's it. It's rather pointless to keep setting the folder permissions to 777 via PHP, when you have already set it to 777.


No, you dont have to change the permissions on the directory each time. Once set, they are set so to speak.

Using 777 is overkill since it gives full permissions to everyone. Remove the 'x' bit and let apache (or whoever) own the directory. This makes it impossible to list files.

0

精彩评论

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