问题
I trying to create some dirs like this:
@mkdir("photos/$cat/$sku", 0777, true)
it creates the first directory with 0777 permissions, but when it creates the second is uses 000 as it's perms, so it fails to create the third.
A workaround this please?
Thanks, Richard.
回答1:
This solved the issue:
$a = @mkdir("photos/$cat/", 0777);
@chmod("photos/$cat/", 0777);
$b = @mkdir("photos/$cat/$sku/", 0777);
@chmod("photos/$cat/$sku/", 0777);
but why can't use recursive on mkdir?
回答2:
I did this and it works perfect:
if (!is_dir($path)) {
$dirs = explode('/', $path);
$i = 0;
$subdir = '';
foreach ($dirs as $dir) {
if($i > 0){$dir = '/' . $dir;}
$subdir .= $dir;
if(!is_dir(DIR_CACHE . $subdir)){@mkdir(DIR_CACHE . $subdir);@chmod(DIR_CACHE . $subdir, 0777);}
$i++;
}
}
So all you have to do is define your path ( $path = photos/$cat/$sku )
回答3:
dear it is due to user rights, please check the user when you are creating the any dir using mkdir function,
回答4:
Have you tried chmod
ing the directories?
mkdir("photos/$cat", 0777, true);
chmod("photos", 0777);
chmod("photos/$cat", 0777);
mkdir("photos/$cat/$sku", 0777);
chmod("photos/$cat/$sku", 0777);
来源:https://stackoverflow.com/questions/2862867/php-mkdir-issue