timlondon Posted August 1, 2007 Share Posted August 1, 2007 The following successfully creates a directory for $path but fails to make a directory for $path2 (without redirecting to fatalerror.php). Anyone know why? $path = "members/".$fl."/".$name; $path2 = "members/".$fl."/".$name."/priv"; mkdir($path, 0755); chmod($path, 0777); if(is_dir($path)) { mkdir($path2, 0755); chmod($path2, 0777); } else { header ("Location: fatalerror.php"); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/ Share on other sites More sharing options...
mrjcfreak Posted August 1, 2007 Share Posted August 1, 2007 You say it successfully creates the directory, but PHP obviously doesn't think it does- are you seeing the directory when you ftp. Is PHP in safe mode? (run phpinfo() and check the safe_mode setting) Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312732 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 $path is successfully created. I can see it if I FTP it. But it won't create the subdirectory. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312735 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 For safemode master value is off but local value is on. Not sure what that means??? Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312737 Share on other sites More sharing options...
mrjcfreak Posted August 1, 2007 Share Posted August 1, 2007 local value = on, I assume, means that your server has PHP safe mode enabled. PHP has a so-called 'Safe-mode' where almost all of it's functionality is crippled. Crucially, you can't make changes inside folders which you make with a script. It's down to permissions and folders you make with PHP having a different group ID making them unusable. It sounds like you're on shared or hosting, and you can't change this setting, in which case there is little you can do except change tactics. Instead of using new directories use funky filenames: so instead of making "bob" inside users/private, make a file called users-DR-private-DR-bob... making sure to use separators that wont be in your "filenames" Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312740 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 I'm on hosting but i can change the ini file. Is it simply a case of switching safemode off?? Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312742 Share on other sites More sharing options...
mrjcfreak Posted August 1, 2007 Share Posted August 1, 2007 Yep. The manual has a fair bit to say about it all: http://uk.php.net/features.safe-mode Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312744 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 Safe modes off (it was off all along) so that's not the problem. Any ideas anyone?? Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312834 Share on other sites More sharing options...
calabiyau Posted August 1, 2007 Share Posted August 1, 2007 Looking at your code you say it is hitting the redirect, which means it is not a problem with creating the folder, since the if statement stops it from ever hitting that portion of the code. The problem must be with is_dir, which I have had problems getting to work before. Maybe try using the full path to the folder including /home/user/...etc. Or try removing the if is_dir clause around the directory functions and see if it works that way. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312842 Share on other sites More sharing options...
l4nc3r Posted August 1, 2007 Share Posted August 1, 2007 Try using an if statement in there, like so: $path = "members/".$fl."/".$name; $path2 = "members/".$fl."/".$name."/priv"; mkdir($path, 0755); chmod($path, 0777); if(mkdir($path2, 0755)) { chmod($path2, 0777); } else { header ("Location: fatalerror.php"); } exit; } Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312856 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 l4nc3r, just tried that. The problems still there. The $path directory is created but the $path2 (a sub folder of $path) isn't. It doesn't redirect to the error page. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312866 Share on other sites More sharing options...
effigy Posted August 1, 2007 Share Posted August 1, 2007 Your mask could be removing permissions. I would see if chmod is working properly, and if not, try removing your mask with umask. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312880 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 Your mask could be removing permissions. I would see if chmod is working properly, and if not, try removing your mask with umask. The chmod seems to work fine. The $path folder which is successfully created is also successfully modded to 0777. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312901 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 I've just noticed that the ownership of the $path directory is user - apache and group - apache. Is this an ownership problem????? Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312967 Share on other sites More sharing options...
effigy Posted August 1, 2007 Share Posted August 1, 2007 What does this tell you about the directory and subdirectory? <pre> <?php print_r(stat('directory_name')); clearstatcache(); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312983 Share on other sites More sharing options...
timlondon Posted August 1, 2007 Author Share Posted August 1, 2007 What does this tell you about the directory and subdirectory? <pre> <?php print_r(stat('directory_name')); clearstatcache(); ?> </pre> It tells me: Array ( [0] => 2053 [1] => 13207891 [2] => 16895 [3] => 2 [4] => 48 [5] => 48 [6] => -1 [7] => 4096 [8] => 1185988020 [9] => 1185988020 [10] => 1185988020 [11] => -1 [12] => -1 [dev] => 2053 [ino] => 13207891 [mode] => 16895 [nlink] => 2 [uid] => 48 [gid] => 48 [rdev] => -1 => 4096 [atime] => 1185988020 [mtime] => 1185988020 [ctime] => 1185988020 [blksize] => -1 [blocks] => -1 ) Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-313000 Share on other sites More sharing options...
effigy Posted August 1, 2007 Share Posted August 1, 2007 Actually, let's try this to get more information (and recursively). Pass it the full path of what you want to check. <pre> <?php function analyze($path) { $dirs = explode('/', $path); foreach ($dirs as $dir) { if ($prev_dir) { $dir = $prev_dir . '/' . $dir; } $stat = stat($dir) or die; $perms = substr(sprintf('%o', fileperms($dir)), -4); $grp_info = posix_getgrgid($stat['gid']); $grp = $grp_info['name']; $usr_info = posix_getpwuid($stat['uid']); $usr = $usr_info['name']; echo "<b>path:</b> $dir<br>"; echo "<b>perms:</b> $perms<br>"; echo "<b>user/group:</b> $usr/$grp<br><br>"; clearstatcache(); $prev_dir = $dir; } } analyze('path/to/my/subdir'); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-313114 Share on other sites More sharing options...
timlondon Posted August 7, 2007 Author Share Posted August 7, 2007 Actually, let's try this to get more information (and recursively). Pass it the full path of what you want to check. <pre> <?php function analyze($path) { $dirs = explode('/', $path); foreach ($dirs as $dir) { if ($prev_dir) { $dir = $prev_dir . '/' . $dir; } $stat = stat($dir) or die; $perms = substr(sprintf('%o', fileperms($dir)), -4); $grp_info = posix_getgrgid($stat['gid']); $grp = $grp_info['name']; $usr_info = posix_getpwuid($stat['uid']); $usr = $usr_info['name']; echo "<b>path:</b> $dir<br>"; echo "<b>perms:</b> $perms<br>"; echo "<b>user/group:</b> $usr/$grp<br><br>"; clearstatcache(); $prev_dir = $dir; } } analyze('path/to/my/subdir'); ?> </pre> Sorry effigy, I was delayed dealing with this problem. I've ran the above and got the following: path: members perms: 0777 user/group: harlow/apache path: members/c perms: 0775 user/group: harlow/apache path: members/c/chukleslondon perms: 0777 user/group: apache/apache I'm assuming that my problem is with the user apache??? If so am I correct in thinking that this is something that my host can resolve??? Am I also correct in the assumption that theoretically I can use mkdir to create a folder and then use mkdir to create a subfolder within that folder???? My host is being very unhelpful so I think I need to go back to them armed with some facts. Your help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-317691 Share on other sites More sharing options...
effigy Posted August 7, 2007 Share Posted August 7, 2007 Which one of these gives you trouble with mkdir? Everything looks OK to me since they're all in the apache group. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-317757 Share on other sites More sharing options...
timlondon Posted August 7, 2007 Author Share Posted August 7, 2007 The problems with chukleslondon. That folder was created by mkdir and chmodded to 777. The script then tries to create a subfolder within chuckleslondon but it simply wont do it. Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-317934 Share on other sites More sharing options...
effigy Posted August 8, 2007 Share Posted August 8, 2007 What user/group is the server running as? apache/apache? The permissions for "chuckleslondon" is 777, which means any one can do anything, such as creating a directory. Have you tried mkdir's recursive argument? Does a terminal/FTP login show you the same user, group, and permission information? Also, going back to mrjcfreak's comment about safe mode, is everything off, including the local = on? Quote Link to comment https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-318489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.