[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){
rmdir($rdir);//Delete empty directories
}else{
return false;
}
}
Return true;
}
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
}
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
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)){
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