views:

51

answers:

2

I have a classifieds website with a picture script for uploading pics onto the ads.

The pics are uploaded to the "images" dir.

The php code which does this requires write access to the directory I am guessing...

So, what permissions would you set to the php upload file, and the images directory?

I am thinking like this:

 drwxr-xr-x 

Safe/good or not?

Thanks

ALSO, another short Q: Should I have my websites files owned by the username I have, or should I keep them owned by root?

+1  A: 

drw-r--r-- (644). Be careful with users being able to push php/other scripting and executable files up to your server.

Be careful with users being able to push js and html files up to your website.

Owned by the username you have for your webserver. Don't make root own files it has no business owning. Root is the adminstrator, not your webserver.

Have a look in your php.ini file for upload_tmp_dir =

Dan McGrath
Okay... but thats my Q, how can I "be careful"... What should I do to prevent them? I have heard about moving the images directory outside my www folder, but haven't looked into it yet. Do you know anything of this?
Camran
Don't allow code to be executed in your upload directory. Confirm images uploaded are actually images. Don't allow any other uploads. Is there a particular reason you need a non image upload directory?
Dan McGrath
no, only images are "supposed" to be uploaded to the directory... What about moving the folder outside www?
Camran
have a look in your php.ini file for 'upload_tmp_dir ='
Dan McGrath
A: 

make a .htaccess with

<Files ^(*.jpeg|*.jpg|*.png|*.gif)>
order deny,allow
deny from all
</Files>

to allow only this files to be uploaded. And check with php function before upload in your code.

Moving the folder outside the www-root is good to. You can make apache the owner also.

source

c-verde