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

php checks and creates multi-level directories

巴扎黑
Release: 2016-11-21 14:27:15
Original
1562 people have browsed it

//检查并创建多级目录
    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;
    }

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template