Home >Backend Development >PHP Tutorial >php checks and creates multi-level directories

php checks and creates multi-level directories

巴扎黑
巴扎黑Original
2016-11-21 14:27:151582browse

//检查并创建多级目录
    function checkDir($path){
        $pathArray = explode('/',$path);
        $nowPath = '';
        array_pop($pathArray);
        foreach ($pathArray as $key=>$value){
            if ( ''==$value ){
                unset($pathArray[$key]);
            }else{
                if ( $key == 0 )
                    $nowPath .= $value;
                else
                    $nowPath .= '/'.$value;
                if ( !is_dir($nowPath) ){
                    if ( !mkdir($nowPath, 0777) ) return false;
                }
            }
        }
        return true;
    }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn