---
title: "php检查并创建多级目录"
author: "kwishly"
date: "2013-11-29T10:40:37Z"
tags: ["PHP"]
categories: ["编程语言"]
slug: "php"
draft: false
lastmod: "2013-11-29T10:40:37Z"
id: 1982800
url: "https://kwishly.iteye.com/blog/1982800"
---

//检查并创建多级目录  
    function checkDir($path){  
        $pathArray = explode('/',$path);  
        $nowPath = '';  
        array\_pop($pathArray);  
        foreach ($pathArray as $key=&gt;$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;  
    }