mkdir and ownership of directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siko
Forum Commoner
Posts: 37
Joined: Tue Feb 16, 2010 11:28 pm

mkdir and ownership of directory

Post 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!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mkdir and ownership of directory

Post 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.
siko
Forum Commoner
Posts: 37
Joined: Tue Feb 16, 2010 11:28 pm

Re: mkdir and ownership of directory

Post by siko »

umask(0) worked perfectly, and I get what you said about the IDs

Thanks for your reply!
Post Reply