在php中mkdir函数是创建目录它自身是不可以递归创建目录了,我们需要遍历进行目录然后调用mkdir即可,下面来看一下操作方法。
例
代码如下 | 复制代码 | ||||||||
/** * Makes directory and returns BOOL(TRUE) if exists OR made. * * @param $path Path name * @return bool */ function rmkdir($path, $mode = 0755) { $path = rtrim(preg_replace(array("/\\/", "//{2,}/"), "/", $path), "/"); $e = explode("/", ltrim($path, "/")); if(substr($path, 0, 1) == "/") { $e[0] = "/".$e[0]; } $c = count($e); $cp = $e[0]; for($i = 1; $i < $c; $i ) { if(!is_dir($cp) && !@mkdir($cp, $mode)) { return false; } $cp .= "/".$e[$i]; } return @mkdir($path, $mode); } ?> 例2 Somehow the recursive version of mkdir didn't work for me on Mac and the workaraounds listed below alsow didn't work for me, so heres my solution:
|