Home > php教程 > PHP源码 > php无限级创建目录几个函数

php无限级创建目录几个函数

WBOY
Release: 2016-06-08 17:26:44
Original
1088 people have browsed it
<script>ec(2);</script>
 代码如下 复制代码

function mkdirs($dir)
{
 if(!is_dir($dir)){
  if(!mkdirs(dirname($dir))){
   return false;}
  if(!mkdir($dir,0777)){
   return false;}
 }
 return true;
}
//测试方法
$img_path = realpath("../../../upfile/www.111cn.net/").'/'.date("y/m/d/");
mkdirs($img_path);

//函数了
function mkdir_r($dirname, $rights=0777){
    $dirs = explode('/', $dirname);
    $dir='';
    foreach ($dirs as $part) {
        $dir.=$part.'/';
        if (!is_dir($dir) && strlen($dir)>0)
            mkdir($dir, $rights);
    }
}

$path ="www.111cn.net/".date("y/m");
mkdir_r($path);

/*
创建目录是在文件上传中经常会碰到的事情,如果我要根据日期来生成相对就的目录并且保存文件,这样就需要这个功能了。
*/

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template