[Original] php + ajax to simulate Win file management system 4. [Original] php + ajax to achieve the simulation of Win file management system this tutorial by the site original, reproduced please indicate the author: www.drise.cn mailbox: drise@163.comQQ: 271728967 above we talked about, de [original] php + ajax to simulate Win file management system
// This tutorial is original on this site. For more information, see here.
Author: www.drise.cn
Email: drise@163.com
QQ: 271728967 //
As we mentioned above,Deletefile () function. next we will talk about the Createfolder () function.
Function Createfolder ($ path, $ nname ){
If (is_dir ($ path) & is_writable ($ path) {// whether the directory is writable
If (preg_match ("/^ \ w {1,255} $/I", $ nname) {// you can determine the validity of a file.
Echo mkdir ($ path. "/". $ nname, 0777 )? 'Create Folder success ': 'Create Folder Fail'; // 0777 sets whether the file can be read or written.
} Else {
Echo "Folder Error ";
}
} Else {
Echo "Can't Create Error file not is_writable or not dir ";
}}
This function is used to create folders,
Past ($ path, $ nname, $ cpath) function
Function Past ($ currentpath, $ currentfilename, $ filepote) {// 1: location where the file is to be pasted 2: current file {folder} name 3: 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'; // The full_copy function is followed by recursive folder reading.
} 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': 'error ';
} If ($ str = "|" & $ t ='t '){
Deldir ($ filepote );
}
}
Function full_copy ($ source, $ target) // This function is from the official site of php and is used to recursively copy files from 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
Author // This tutorial by the site original, reproduced please indicate the author: www.drise.cn mailbox: drise@163.com QQ: 271728967 // above we talked about, De...