开发者

PHP mkdir issue!

开发者 https://www.devze.com 2022-12-31 19:08 出处:网络
I trying to create some dirs like this: @mkdir(\"photos/$cat/$sku\", 0777, true) it creates the first directory with 0777开发者_如何学Go permissions, but when it creates the second is uses 000 as i

I trying to create some dirs like this:

@mkdir("photos/$cat/$sku", 0777, true)

it creates the first directory with 0777开发者_如何学Go 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.


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?


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 )


dear it is due to user rights, please check the user when you are creating the any dir using mkdir function,


Have you tried chmoding the directories?

mkdir("photos/$cat", 0777, true);
chmod("photos", 0777);
chmod("photos/$cat", 0777);
mkdir("photos/$cat/$sku", 0777);
chmod("photos/$cat/$sku", 0777);
0

精彩评论

暂无评论...
验证码 换一张
取 消