[原創]php+ajax實現模擬Win文件管理系統
//本教程由本站原創,轉載請注明來處
作者:www.drise.cn
QQ:271728967//
上面我們講到了,Deletefile()函數,下面我們接著講Createfolder()函數
function Createfolder($path,$nname){
if(is_dir($path) && is_writable($path)){//是否為目錄且可寫
if(preg_match("/^\w{1,255}$/i",$nname)){//判斷文件的合法性
echo mkdir($path."/".$nname,0777)?'Create Folder success':'Create Folder Fail';//0777是設置文件可讀寫
}else{
echo "Folder Error";
}
}else{
echo "Can't Create Error file not is_writable or not dir";
}}
這個函數的功能是實現文件夾的建,
Past($path,$nname,$cpath)函數
function Past($currentpath,$currentfilename,$filepote){ //1:文件要被粘貼到的位置2:當前文件{夾}名3:文件{夾}所在的物理地址
$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函數下面接,是進行遞歸讀取文件夾
}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);
}
}
function full_copy( $source, $target )//這個函數來自php官方站,功能是進行文件夾遞歸拷貝文件
{
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 );
}
}
上一篇