File permissions problem

Hello there!

I have been trying to give permissions to my uploaded files. The problem is I can’t view the images I upload.

I have a directory… uploads/file(number)/image

I click on uploads folder and file permissions and 7 5 5 execute and read to all!

Even if i check these permissions on uploads folder, that permissions don’t go beneath folders = file(number)/image.

If I click an image and set file permissions then I can’t view the image but that’s not the idea as you can approve…

Files and images under uploads folder must be all check as read and execute… But that s my problem…

How can I check all under (uploads) files as read/execute?

Thanks a lot in advance!!!

Hi hal7,

Welcome to the SitePoint forums!

You need to determine what users Apache is running under. Sometimes this is root (often represented by 0) or sometimes this is another user like www. If the user that your granting permissions to is different than the Apache user then it does not matter what permission you give the web-server will still not have rights.



Welcome to SitePoint!

To give further explanation to Steve’s, the permissions are given in a matrix with values: Read (4), Write (2) and Execute (1). These are obviously binary so their addition can designate the permissions granted to: Owner, Group and Guest.

As a rule of thumb, you NEVER want to grant anyone but yourself Write permission so either a 4 (in general) or 5 (only allow PHP scripts to be executable … and they generally don’t even require that designation. Thus, 644 or 755 are common - unless you want to bar visitors from viewing in which case 600 would be what you would use. Just remember NEVER to give yourself a non-write code or you’ll have difficulty resetting that without cPanel’s File Manager (or the like).

When you set a directory with the 644 (or 755), that will be assigned to any file added so that’s likely the problem you’re running into.



Thanks! I will definitely learn a lot on this forum!

I think I kind of understood what you guys try to explain… Maybe I should give more information about the problem…

My system is adding adds to website. This adds are added in a file in "uploads folder. and An image of the add is added in the folder of an add in uploads folder:


My problem is: I click on uploads folder and I give the permission: 755 read to all and execute to all. And apply this to all below files.

When the user creates a new add (so a new add file) that file doesn’t get that 755 permission.

New created file gets 744 as default and so you can’t view the image…

What do I have to do so that a new created file get 755 permission as default?

Thank you very much for your time!


First, did you change the permissions on the adds folder to 766 as suggested? It MUST have write permission for the (Apache) user.

Okay, saying that, I’m more concerned about what you didn’t say: That you confirm that the file was uploaded (to the server’s upload directory) then READ by imagecreatefromjpeg, resized and then written to your adds folder. This will ensure that the uploaded image was uploaded and was a JPG file with the additional benefit of ensuring that it is an appropriate size.

If you’re not checking the upload files in this manner, you’re inviting hackers to deposit “payloads” on your server to spread across the Internet.



Yes I did change the the permission of the uploaded adds then I do not get problem with viewing images!
Because the permission is changed to readable.

I cannot view images unless I don’t change the permission of an add manually!

So problem is the adds get permission as unreadable as default.

and what you are concerned is unnecessary because I have set all the security checks in my php code. (Like check size and format of the file)

Plus I ve asked this problem to my hosting company they can’t solve it either:s

I am desperate! :frowning:

By the way,

I have .httaccess(Options -Indexes ) file in uploads folder. Do I have to change it or something maybe?


That seems to be an unusual setup on your server. If this is hosted, ask your support team for help as new files should receive the same permission as the folder. Perhaps using PHP to change the file permission after storing in the folder?

Unnecessary? Ha! Any script kiddie can hide a “payload” in an image file and the file type will report the appropriate image definition. THAT is why I recreate any image uploaded to my server. I may be paranoid but there are script kiddies out there looking for kicks and I don’t want to be a willing target.

First, the filename is .htaccess (not two t’s - presumably a typo) then Options -Indexes merely forbids Apache from providing a directory listing so it has nothing to do with this problem.



Hey dklynn,

Thanks voor the answer. I have passed the problem to my host but they couldn’t figure it out yet :s

What kind of php code you can tip to change file permission?

Sorry I didn’t mean like it is not important with unnecessary but I meant I have done all those things you are concerned about. :slight_smile:

I hope I will be able to solve this problem soon …

Thanks alot!



Go to for:

Yes, they’ve got plenty of examples, too.

BTW, IMHO has the best documentation anywhere so bookmark your local version and learn to guess the function you’re looking for.



Thanks DK!

I ll be on it!

Cool DK,

I’ve used these commands in Linux a very long time, however I never thought to see if PHP had commands for these. Well you learn something new most days, so thank you.



Glad to help!