[Original] PHP+ajax implements simulated Win file management system 5_PHP tutorial

WBOY
Release: 2016-07-13 11:00:02
Original
1001 people have browsed it

[Original] php+ajax implements simulated Win file management system

//

This tutorial is original from this site, please indicate the source when reprinting

Author: www.drise.cn

Email:drise@163.com

QQ:271728967

//

This is the deldir() function. The function of this function is to delete files

function deldir($dir){


If(is_dir($dir)){


         $rdir = $dir;


If($dirlist = scandir($rdir)){ //Scan directory
                 array_shift($dirlist);Remove ".."
                 array_shift($dirlist);Remove "."
foreach($dirlist as $d){


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


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


​​​​​unlink($rd);//Delete file


           }else{


​​​​​deldir($rd);//Recursion


         }


                                                                                               

​​​​​​ rmdir($rdir);//Delete empty directories

         }else{

              return false;

}

}

Return true;

}

This function also uses a recursive algorithm to delete directories and files,

The following is the filename() function. The function of this function is to rename the file

function Filename($path,$nname){

// Get the old file name

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

exit('Illegal operation!');

}else{

$oname = substr($path,strrpos($path,"/")+1);
$opath = substr($path,0,strlen($path) - strlen(substr($path,strrpos($path,"/")+1)));//Get the current path of the file

}

//Rename

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)){ //Match file name

Rename_file_folder($path,$opath,$nname);//These functions are discussed below

}else if( preg_match("/^w{1,255}$/i",$nname,$temp_name) && preg_match("/^w{1,255}$/i",$oname,$otemp_name)){ //Match folder 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";
}
}

}

Previous article

http://www.bkjia.com/PHPjc/631852.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631852.htmlTechArticle[Original] php+ajax implements simulated Win file management system // This tutorial is original from this site, please note when reprinting Ming Lai Chu Author: www.drise.cn Email: drise@163.com QQ:271728967 // This is the deldir() function...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template