Page 1 of 1

mkdir and ownership of directory

Posted: Sat Aug 21, 2010 4:11 am
by siko
Hi all,

I'm new to permissions and ownership of files/folders.

I would like to create a new folder for each inidividual user that registers on my website, this folder will store their upload profile pictures, testimonials, certificates etc.

So for a user with user id 912, I'll create a folder: client_profile/912/

A profile picture will have the path: client_profile/912/912_profile_pic.jpg

I'm using the following to create the folder

Code: Select all

mkdir ($uploadsDirectory, 0777);
That creates a folder that sets permission to 0755, and has owner set to 80, group as 1646.

1) I know what's 0755, but why is it created with 0755 permission when i used 0777 in my mkdir function?

Well the problem here is that, I'm using an ftp client to look at my directories, and it seems i am not allowed to delete/move/rename/paste files that are in folders that have owner set to 80. Or maybe there are other factors, but i should say that's the only difference I can see between folders which have this problem and folders that don't. Folders that I manually created through my ftp client have owner set to 1646, these folders have no such problem.

2) Can anyone explain to me what does the owner and group code means?

3) As the site admin shouldn't I have access to every file on the site?

4) If ownership of 80 is indeed the problem here, can I create the directory with ownership set to 1646?

Many thanks in advance!

Re: mkdir and ownership of directory

Posted: Sat Aug 21, 2010 6:52 am
by requinix
1. mkdir is affected by the umask, which is often 0022. 0777 & ~0222 = 0755 and that's what you end up with.
Try umask(0);

2. If I'm understanding you correctly, the owner and group IDs are the numeric equivalents to usernames and groupnames respectively. I, for example, am "tasairis" with user ID 43249 on this site.

3. It's more complicated than that. There are two people using "your site": the webserver (probably user ID 80) and you (probably user ID 1646). When one of them creates stuff it belongs to them, which is the reason you're "taught" to chmod 0777 directories when they're created: it gives read/write access to everybody, not just the creator/owner.

4. No.

Re: mkdir and ownership of directory

Posted: Wed Sep 01, 2010 3:53 am
by siko
umask(0) worked perfectly, and I get what you said about the IDs

Thanks for your reply!