[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//
So here we go, thedeletefile () function, and then we'll go on to the CreateFolder () function
function CreateFolder ($path, $nname) {
if (Is_dir ($path) && is_writable ($path)) {//is a directory and writable
if (Preg_match ("/^\w{1,255}$/i", $nname)) {//judge the legality of the document
echo mkdir ($path.) /". $nname, 0777)? ' Create folder Success ': ' Create folder Fail ';//0777 is the set file can read and write
}else{
echo "Folder Error";
}
}else{
echo "Can ' t Create Error file not is_writable or not dir";
}}
The function of this function is to implement the construction of the folder,
Past ($path, $nname, $cpath) function
function Past ($currentpath, $currentfilename, $filepote) {//1: Where the file is to be pasted 2: The current file {folder} Name 3: The physical address of the file {folder}
$str = substr ($currentfilename, -1,1);
if (substr ($currentfilename, -1,1) = = "|") {
$currentfilename = Str_replace ("|", "", $currentfilename);
$filepote = Str_replace ("|", "", $filepote);
}
if (Is_dir ($currentpath) && is_writable ($currentpath) && is_dir ($filepote) && is_writable ($ Filepote)) {
@mkdir ($currentpath. " /". $currentfilename);
$t =full_copy ($filepote, $currentpath. " /". $currentfilename)? ' T ': ' f ';//full_copy function Next, is to read the folder recursively
}else if (Is_file ($filepote) && file_exists ($filepote)) {
if (File_exists ($currentpath. $currentfilename)) {echo (' file exists! plase rename it! '); Exit;}
echo Copy ($filepote, $currentpath. $currentfilename)? ' Success ': ' Errror ';
} if ($str = = "|" && $t = ' t ') {
Deldir ($filepote);
}
}
Functions Full_copy ($source, $target)//This function is from the PHP official station, the function is to make the folder to copy files recursively
{
if (Is_dir ($source))
{
@mkdir ($target);
$d = Dir ($source);
while (FALSE!== ($entry = $d->read ()))
{
if ($entry = = '. ' | | $entry = = ' ... ')
{
Continue
}
$Entry = $source. '/' . $entry;
if (Is_dir ($Entry))
{
Full_copy ($Entry, $target. '/' . $entry);
Continue
}
Copy ($Entry, $target. '/' . $entry);
}
$d->close ();
}else {
Copy ($source, $target);
}
}
Previous article