分享一个php代码创建目录的Demo

/*
 * 连续建目录
 * string $dir 目录字符串
 * int $mode 权限数字
 * 返回:顺利创建或者全部已建返回true,其它方式返回false
 */
function makeDir( $dir_path, $mode = "0777" ) {
    //如:路径("c:/testweb/wap/home.php"), 我们要创建的目录》c:/testweb/wap,所以在上面$dir_path='c:testweb/wap'即可
    if( ! $dir_path ) return 0;
    $dir_path = str_replace( "\", "/", $dir_path );
    $mdir = "";
    foreach( explode( "/", $dir_path ) as $val ) {
        $mdir .= $val."/";
        if( $val == ".." || $val == "." || trim( $val ) == "" ) continue;
        if( ! file_exists( $mdir ) ) {
            if(!@mkdir( $mdir, $mode )){
                return false;
            }
        }
    }
    return true;
}
原文地址:https://www.cnblogs.com/xuzhengzong/p/7269318.html