[Original]PHP+AJAX implementation simulation win file management system five

Source: Internet
Author: User

[Original]php+ajax to realize the simulation win file management system

//

This tutorial by the original site, reproduced please specify the place

Author: www.111cn.net

Email: drise@163.com

qq:271728967

//

The function of the Deldir () function is to delete the file

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 directory


}else{


return false;


}


}


return true;


}

This function also uses the recursive algorithm, carries on the directory and the file deletion,

Here is the filename () function, which is the function of renaming the file

function Filename ($path, $nname) {

Get 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

}
Renaming

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)) {//matching filename

Rename_file_folder ($path, $opath, $nname)//Some functions are mentioned 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.