Home >Backend Development >PHP Tutorial >[Original] PHP+ajax implements simulated Win file management system 4_PHP tutorial

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

WBOY
WBOYOriginal
2016-07-13 11:00:00813browse

[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 talked about the Deletefile() function above. Now let’s talk about the Createfolder() function

function Createfolder($path,$nname){
if(is_dir($path) && is_writable($path)){//Whether it is a directory and writable
if(preg_match("/^w{1,255}$/i",$nname)){//Determine the legality of the file
echo mkdir($path."/".$nname,0777)?'Create Folder success':'Create Folder Fail';//0777 is the setting file that can be read and written
}else{
echo "Folder Error";
}
}else{
echo "Can't Create Error file not is_writable or not dir";
}}

The function of this function is to create a folder,

Past($path,$nname,$cpath) function

function Past($currentpath,$currentfilename,$filepote){ //1: The location where the file is to be pasted 2: The name of the current file {folder} 3: The physical address where the file {folder} is located
$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';//The full_copy function is followed below, which is to recursively read the folder
}else if(is_file($filepote) && file_exists($filepote)){
If(file_exists($currentpath.$currentfilename)){ echo ('file exists! place rename it!');exit;}
Echo copy($filepote,$currentpath.$currentfilename)?'success':'errror';
} if( $str == "|" && $t='t' ){
deldir($filepote);
}
}

function full_copy( $source, $target )//This function comes from the php official website, and its function is to recursively copy files in folders
{

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631853.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// As we mentioned above, De...
Statement:
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