Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mkdir() problems

Status
Not open for further replies.

rockstardub

Programmer
Dec 29, 2004
42
US
I don't know how to make a directory on my website with a php page without changing the permissions to 777, please help!
 
the directory in which you wish to create a subdirectory must allow the apache process (assuming apache) the relevant permissions. apache normally runs as "nobody" or sometimes "apache". make sure create directory premissions are granted to the relevant user.

you can also (and should) set the mode for the soon to be created directory as part of the mkdir call.
Code:
mkdir("/path/to/my/dir", 0700); //from php.net. NOTE: if mode is not specified it defaults to 0777

note that if you are using umask() you will have to take the offset into account in the mode.

note also that the entire path to the new directory needs to be provided as the function is not natively recursive. if you want to make it recursive then you can add a true flag after the mode. beware that this means the apache user needs permissions down to wherever the recursion is due to start.
 
Im guessing this is exactly what i need to hear, and my hours of research have taken me down the same path as what you're recommending, but I dont understand it in actuallity.

What I know, my group is "myiroomc", both the files when I use FTP and when using php uploading and changing the group using chgrp().
The user for my FTP files is also myiroom but the php uploaded files stay under the user "80" reguardless of chown() attempts.
I am using a hosting service, ipower.com, so I don't have full access to apache files.
So...

Yes, I am running apache,
what is apache process?
"make sure create directory premissions are granted" how?
to the relevant user - who is that? why not 0755?
set the mode?
this is the code I was using, and it was acurate.
mkdir($newdir, 0755);

what is umask()?
take the offset into account in the mode. huh?
recursive?
true flag?
who is the apache user?

Also, my FTP client won't allow me to delete files owned by "80" how do I fix this?

Thanks much for your help.
 
im not a unix user but a brief google for linux permissions through up this helpful manual:


the apache user is normally "nobody"

for umask() check out the php.net site
recursive: linux doesn't work like windows. if you tell windows to make a directory in a parent that doesn't exist it will create the parent and the subdirectory without quibbling. this is a recursive operation in how it is performed.

in linux you would normally have to create each parent and then the child. with the recursive flag set to true ( the function will mimic the windows behaviour of creating any directory that is needed.

i can't answer for your ftp client but i suspect that the files are not owned by the ftp service user. try logging in to the box as root and testing things.

it is possible that this is not a box that you own and instead it may be a hosted service. if this is the case, armed with the php knowledge and having read the permissions link above i'd suggest you take the permissions problem to your service provider. they are most equipped to help you resolve them as they can get root access to the box and/or explain how they have configured it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top