Home >php教程 >php手册 >[原创]php+ajax实现模拟Win文件管理系统五

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

WBOY
WBOYOriginal
2016-06-13 09:59:171180browse

[原创]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";
  }
 }

}

上一篇

Statement:
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