PHP头条
热点:

[原创]php+ajax实现模拟Win文件管理系统五


[原创]php+ajax实现模拟Win文件管理系统

//

本教程由本站原创,转载请注明来处

作者:www.drise.cn

邮箱:drise@163.com

QQ:271728967

//

就是deldir()函数了这个函数的功能是删除文件

function deldir($dir){


    if(is_dir($dir)){


        $rdir = $dir;


        if($dirlist = scandir($rdir)){ //进行扫描目录
              array_shift($dirlist);去除".."
              array_shift($dirlist);去除"."
        foreach($dirlist as $d){ 


         $rd = $rdir.'/'.$d;


         if(isset($d) && is_file($rd)){ 


          unlink($rd);//删除文件


         }else{


          deldir($rd);//递归


         }


        }  


            rmdir($rdir);//删除空目录


        }else{


            return false;


        }


    }


    return true;


}

 

这个函数也用了递归算法,进行目录与文件的删除,

下面就是filename()函数了,这个函数的功能是对文件进行重命名

function Filename($path,$nname){

  // 取得旧文件名

 if($path == "" || substr($path,-1) =="/" || strlen($path)>255){

  exit('非法操作!');

 }else{
  $oname = substr($path,strrpos($path,"/")+1);
  $opath = substr($path,0,strlen($path) - strlen(substr($path,strrpos($path,"/")+1)));//获取文件的当前路径  

 }
  //重命名

 if(preg_match("/^\w{1,255}\.\w{1,8}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}\.\w{1,8}$/i",$oname,$otemp_name)){ //匹配文件名

  Rename_file_folder($path,$opath,$nname);//些函数下面讲到

 }else if( preg_match("/^\w{1,255}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}$/i",$oname,$otemp_name)){ //匹配文件夹名
  Rename_file_folder($path,$opath,$nname);
 }else{
  echo("File info Error");

 }}

function Rename_file_folder($path,$opath,$newname){
 if(is_dir($path)){
  if(is_writable($path)){

   if(is_dir($opath.$newname)){ exit("Sorry Dir is exists");}
   echo rename($path,$opath.$newname)?'Rename Success':'Rename Fail Error';
  }else{
   echo('Can\'t Rename dir not is_writable');

  }
 }else{
  if(file_exists($path) && is_writable($path)){
   if(file_exists($opath.$newname)){ exit("file exists"); }
   echo rename($path,$opath.$newname)?'Rename success ':'Rename fail';
  }else{
   echo "file can't is_writable";
  }
 }

}

上一篇

www.phpzy.comtrue/php/23899.htmlTechArticle[原创]php+ajax实现模拟Win文件管理系统五 [原创]php+ajax实现模拟Win文件管理系统 // 本教程由本站原创,转载请注明来处 作者:www.drise.cn 邮箱:drise@163.com QQ:271728967 // 就是deldir()函数了这个函...

相关文章

    暂无相关文章

PHP之友评论

今天推荐