Jump to content

Recommended Posts

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;

}

 

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/
Share on other sites

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"

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312740
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312842
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-312856
Share on other sites

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 )

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-313000
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-313114
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-317691
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/62824-mkdir-issue/#findComment-318489
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.