Page 1 of 1

dir permissions

Posted: Thu Oct 21, 2004 2:20 pm
by liquid
Hello,

Heres what I need to happen:

I have a file uploader. It uploads images to the specified dir just fine. The following is the code:
-------------------------

Code: Select all

$pathname = "uploads/".$cname; //$cname = the name of the facility
if (is_dir($pathname)) { 
	//return true;  
	 
}else{
	$oldumask = umask(0); 
	mkdir("uploads/".$cname, 0777);
	umask($oldumask);
	
}
------------------------
Heres what happens:
First a list of Doctors is displayed.

Second the admin person chooses which doctors office he wants to upload the file to.

Third - After the admin clicks on the dr's link it checks to see if there is a dir already created for that dr's office. If not then it creates the dir and uploads the specified file, which is working, but Im getting an error stating permissions denied. So the dir with the drs office name is being created but the file that is being uploaded is put into the "uploads" dir not the drs dir. I thought the '0777' set the permissions of the new dir to be fully writable? its not!

Any help would be great so my head doesnt explode!
Thanks
liquid

Posted: Thu Oct 21, 2004 2:24 pm
by Weirdan
and what permissions are set on newly created dir?

Posted: Thu Oct 21, 2004 3:07 pm
by liquid
Well, I thought by creating the dir using the following code
mkdir("uploads/".$cname, 0777);
set the newly crated dir to "The mode is 0777 by default, which means the widest possible access." <-- from php.net

right now the only way I can seem to get full permissions is by going to the dir through an ftp client and manually changing the permissions, but that wont work because it needs to be dynamic.

Im going to try to create the dir then run the following to see if that changes the permissions to fully writable.
chmod("uploads/".$cname", 0777);

Posted: Thu Oct 21, 2004 3:10 pm
by liquid
chmod("uploads/".$cname", 0777); did not help :(

Posted: Thu Oct 21, 2004 4:00 pm
by rehfeld
is safemode on?

if so, theres your problem.

i may be wrong, but i dont beleive you can make a directory and then use it like that, if safemode is on. I remember the same problem, and the only solution i could find was to use ftp to make the directories(or through your controll panel). The reason that would work, is because then the owner of the directory is the ftp user, instead of php. With safemode on, since the user php(usually runs as the user 'nobody') could also be someone on the same shared server trying to screw your site, so it denies the operation. file permissions will not help. Changing the owner of the file will.

you can read more about safemode on the php.net site

Posted: Thu Oct 21, 2004 4:02 pm
by rehfeld
oh and chown($dir) wont work if your doing it from php, because again, the user 'nobody' wont be allowed to do that. yes, its a pain. shared hosting sucks.

Posted: Thu Oct 21, 2004 4:25 pm
by liquid
ARGG...OK.. can I make a call with php to make safemode is off? After looking at php.net I could not find a clear example of how to to do that.

Thanks for your help.

Posted: Thu Oct 21, 2004 5:04 pm
by rehfeld
cant, its in php.ini

i highly doubt your host would be willing to change it either.


this would be a hack fix, but you "could" create a new ftp account, say autophp




make a script which uses php ftp functions to log into your site, make the directory, then log out.

dirmaker.php?dir=your/desired/dir

have dirmaker.php echo 'true' if its successfull, or false

then in your script that you origioanlly wanted to be making the dir

Code: Select all

$make_dir = file_get_contents('http://example.org/dirmaker.php?dir=foo');

if ($make_dir === 'true') {
    // it worked, but it probably made your script hang for 15 seconds while it waited for dirmaker.php to log in through slow ass ftp and do its thing
}
ive never done that, but should only take a half hour or so of coding. Im not sure if you can log into your own site from within a script in your own site, so you might need to place dirmaker.php at either a diff host, or maybe just a diff url. thats why i used file_get_contents(), cause im guessing you cant.

but if you can, that should work pretty good, and quickly because you could just call it as a function, or include dirmaker.php etc...

make sense? i know i babble lol

feyd | start using the forum provided php highlighting.

Posted: Thu Oct 21, 2004 5:16 pm
by liquid
babble is good :) it does make sense and thanks for the suggestion.

Just FYI, I did get the dir created with full permissions, but...of course theres always a but....the file I try to upload to that newly created dir does not go in the folder but instead sits one level up. So either my pathing is off (which Ive echoed a thousand times and always comes back correct and still doesnt go in the damn folder) or like you've said its just not possible!

Ill keep on trying and let you know if your idea works for me.

Thanks