PHP mkdir() and permissions
I'm creating a new folder with file permission 0777, and attempting to create subdirectories within it:
<?php
$uCatArray = array(\"one\",\"two\",\"three\");
$bizFolder = \"rootFolder\";
$si = sizeof($uCatArray);
if (!is_dir (\"$bizFolder\")){
umask(0000);
$bDir=mkdir($bizFolder, 0777);
for ($i=0;$i<$si;$i++){
$subBDir=\"$bizFolder\" . \"/\" . $uCatArray[$i];
if (!is_dir(\"$subBDir\")){
umask(0000);
$sDir = mkdir($subBDir,0777);
// umask($sDir);
echo $subBDir . \"<br>\";
}
}
}
?>
The subdirectories are not being created, this is the message:
SAFE MODE Restriction in effect. The script whose uid is 743 is not allowed to access ../rootFolder
How can I work around this make the subdirectories?
Thanks,
TonyMontana
druagord posted this at 22:27 — 19th August 2003.
He has: 335 posts
Joined: May 2003
the folder in wich you are trying t create a new one must have write permission for the webserver user since it's the user who is going to create the folder
IF , ELSE , WHILE isn't that what life is all about
TonyMontana posted this at 00:10 — 20th August 2003.
They have: 218 posts
Joined: Apr 2001
Yes, I changed that and $bizFolder is now being created.
But when attempting to create the subFolders within that folder, this warning is happening:
Warning: SAFE MODE Restriction in effect. The script whose uid is 743 is not allowed to access someFolder owned by uid 48
So how can subdirectories be created??
Cheers,
TonyMontana
TonyMontana posted this at 08:07 — 20th August 2003.
They have: 218 posts
Joined: Apr 2001
The only workaround I've seen, without switching SAFE MODE off is conncting via ftp_connect(), which appears to work thus far, although it is a more clunky way of working.
TM
druagord posted this at 12:57 — 20th August 2003.
He has: 335 posts
Joined: May 2003
could you suply what the resulting permission from the first folder are. from what i see they should be 777 but the warning seems to say otherwise
m3rajk posted this at 17:37 — 20th August 2003.
They have: 461 posts
Joined: Jul 2003
i agree with druagord here. it sounds like the issues is that it doesn't have permission, which means that the call to the folder when being created is setting permissions wrong. double check that it's being set to 777, or that the webserver has rwx (needs all three because you need r-x to read the folder and w to write to it. the other groups permissions are moot in this case)
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
TonyMontana posted this at 18:08 — 20th August 2003.
They have: 218 posts
Joined: Apr 2001
'it sounds like the issues is that it doesn't have permission, which means that the call to the folder when being created is setting permissions wrong'
Actually the initial folder is created, with file permission 0777. It's the subdirectories within it that are not being made due to a limitation in SAFE MODE where the server takes ownership of the new folder, and restricts access to the php script which has a different uid.
Cheers,
TM
m3rajk posted this at 18:37 — 20th August 2003.
They have: 461 posts
Joined: Jul 2003
if other is set to rwx, then regaurdless of who OWNS the folder, everyone has complete access. i believe safemode only checks uid, and gid (optional)
so there IS something you can do, if it's set to chec gid, then set the gid of the server and php to be the same. at this point it will be able to in safe mode
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
TonyMontana posted this at 18:52 — 20th August 2003.
They have: 218 posts
Joined: Apr 2001
'if it's set to chec gid, then set the gid of the server and php to be the same. at this point it will be able to in safe mode'
m3rajk, can you explain exactly how to access and change those settings?
TM
druagord posted this at 19:19 — 20th August 2003.
He has: 335 posts
Joined: May 2003
Are you running PHP in cgi or as a module if it's as a module the first folder should be created with the user under under wich apache is running as the owner and the subfolder too.
after carefully checking the error message i am wondering if .. in ../rootFolder is correct i don't see where it comes from in the script
IF , ELSE , WHILE isn't that what life is all about
m3rajk posted this at 19:32 — 20th August 2003.
They have: 461 posts
Joined: Jul 2003
/etc/php.ini (if you're on a posix box) has the php settings. make sure safe mode does gid checking as well as uid.
if not, and you're not root, then youhave to talk to root for both things.
root has to set groups. i believe they need to have the same primary group to automatically work right. that's inthe user/group mantainence
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
TonyMontana posted this at 19:47 — 20th August 2003.
They have: 218 posts
Joined: Apr 2001
Thanks. For now I'll stick with this approach, because I know close to nothing about the setup and settings. And this works, .
<?php
$uCatArray = array(\"one\",\"two\",\"three\");
$si = sizeof ($uCatArray);
$connection = ftp_connect('ftp.yoursite.com');
$username = 'username';
$pass = 'password';
$login_result = ftp_login($connection,$username,$pass);
// check to make sure you're connected:
if ((!($login_result)) or (!($connection)))
{
echo \"no login\";
}
else
{
// create root folder
$rootFolder=\"sumFolder\";
$dir = '/var/www/html/anotherFolder/';
ftp_chdir($connection,$dir);
echo \"Current directory is now : \", ftp_pwd($connection), \"\n\";
if(ftp_mkdir($connection,$rootFolder)) print (\"File is created!\");
$chmod_cmd=\"CHMOD 0777 \".$rootFolder;
$chmod=ftp_site($connection, $chmod_cmd);
}
// change to new folder
ftp_chdir($connection,$rootFolder);
for ($i=0;$i<$si;$i++){
$newDir = $dir . $rootFolder . \"/\" . $uCatArray[$i];
//ftp_chdir($connection,$dir);
if(ftp_mkdir($connection,$newDir)) print (\"File is created!\");
$chmod_cmd=\"CHMOD 0777 \".$uCatArray[$i];
$chmod=ftp_site($connection, $chmod_cmd);
}
ftp_quit($connection);
?>
m3rajk posted this at 20:04 — 20th August 2003.
They have: 461 posts
Joined: Jul 2003
np. if you'd like some help with posix, i know that to some degree (i've done sys ad work) so i can try to guide you, but if you're not root, then it's moot. you'd need your sys ad to do the stuff
just an fyi, here's the section of the ini that deals with the gid:
POSIX. because a stable os that doesn't have memory leaks and isn't buggy is always good.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.