Home > php教程 > php手册 > body text

支持多级目录建立的php函数

WBOY
Release: 2016-06-13 11:24:43
Original
715 people have browsed it

支持多级目录建立的php函数本函数php自定义函数是一款建立文件夹的路径并且支持多级目录实例函数哦。

支持多级目录建立的php教程函数
本函数php自定义函数是一款建立文件夹的路径并且支持多级目录实例函数哦。

 * create_dir(建立文件夹的路径,支持多级目录);
 */
 function create_dir($dir_adds='') {
  $falg = true;
  $dir_adds  = trim($dir_adds);
  if($dir_adds!=''){
   $dir_adds = str_replace(array('//','','\'),'/',$dir_adds);
   if (!is_dir($dir_adds)) {
    $temp = explode('/',$dir_adds);
    $cur_dir = '';
    for($i=0;$i     $cur_dir .= $temp[$i].'/';
     if (!@is_dir($cur_dir)) {
      if(!@mkdir($cur_dir,0777))
       $falg = false;
     }
    }
   }
   return $falg;
  }
 }
 
 //看一款目录检测并写文件函数
 
 function htm_w(
    $w_dir = '',
    $w_filename = '',
    $w_content = ''
   ){

  $dvs  = '';
  if($w_dir && $w_filename && $w_content){
   //目录检测数量
   $w_dir_ex  = explode('/',$w_dir);
   $w_new_dir = ''; //处理后的写入目录
   unset($dvs,$fdk,$fdv,$w_dir_len);
   foreach((array)$w_dir_ex as $dvs){
    if(trim($dvs) && $dvs!='..'){
     $w_dir_len .= '../';
     $w_new_dir .= $dvs.'/';
     if (!@is_dir($w_new_dir)) @mkdir($w_new_dir, 0777);
    }
   }


   //获得需要更改的目录数
   foreach((array)$this->filedir as $fdk=>$fdv){
    $w_content = str_replace($fdv,$w_dir_len.str_replace('../','',$fdv),$w_content);
   }
   $this->writer($w_dir.$w_filename,$w_content);
  }
 }
 ?>


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!