PHP mkdir issue!

主宰稳场 提交于 2020-01-14 22:45:52

问题


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


来源:https://stackoverflow.com/questions/2862867/php-mkdir-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!