[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//
We have already talked about the function of the dir.php file in the previous article. Now I will talk about the function of each function of the rename.php file.
Refere();
header("Content-type:text/html;charset=utf-8");//Set document encoding
$path = isset($_GET['path'])?$_GET['path']:'';
$nname = isset($_GET['nname'])?$_GET['nname']:'';
$cpath = isset($_GET['copypath'])?$_GET['copypath']:'';
$action = isset($_GET['action'])?$_GET['action']:'';
switch($action){
case 'del':
Deletefile($path);
break;
case 'mkdir':
Createfolder($path,$nname);
Break;
case 'past':
Past($path,$nname,$cpath);
Break;
default:
Filename($path,$nname);
}
Here are all the functions of the rename.php file, let’s analyze them below.
Refere() function
Very many people will probably know the purpose when they see the name. Let’s look at its code below.
function Refere(){
$referer=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'';
if($referer =='' || is_null($referer) || empty($referer)){
exit("Error Server Http 500");
}
}
In this short paragraph, here is the most basic security protection method to prevent users from directly entering the rename.php file. I will not talk about the functions.
Deletefile() function
function Deletefile($path){
if(is_dir($path) && is_writable($path)){
echo @rmdir($path)?'t':'fo';
}else if(file_exists($path) && is_writable($path)){
echo unlink($path)?'t':'ff';
}else{
exit("No permission, Error http 404 ");
}
}[The t and ff outputted above are used to judge the subsequent returns by passing values using ajax, and display the results to the user.]
Previous article