[原創]php+ajax實現類比Win檔案管理系統五_PHP教程

來源:互聯網
上載者:User
[原創]php+ajax實現類比Win檔案管理系統

//

本教程由本站原創,轉載請註明來處

作者:www.drise.cn

郵箱:drise@163.com

QQ:271728967

//

就是deldir()函數了這個函數的功能是刪除檔案

function deldir($dir){


if(is_dir($dir)){


$rdir = $dir;


if($dirlist = scandir($rdir)){ //進行掃描目錄
array_shift($dirlist);去除".."
array_shift($dirlist);去除"."
foreach($dirlist as $d){


$rd = $rdir.'/'.$d;


if(isset($d) && is_file($rd)){


unlink($rd);//刪除檔案


}else{


deldir($rd);//遞迴


}


}


rmdir($rdir);//刪除空目錄


}else{


return false;


}


}


return true;


}

這個函數也用了遞迴演算法,進行目錄與檔案的刪除,

下面就是filename()函數了,這個函數的功能是對檔案進行重新命名

function Filename($path,$nname){

// 取得舊檔案名稱

if($path == "" || substr($path,-1) =="/" || strlen($path)>255){

exit('非法操作!');

}else{
$oname = substr($path,strrpos($path,"/")+1);
$opath = substr($path,0,strlen($path) - strlen(substr($path,strrpos($path,"/")+1)));//擷取檔案的當前路徑

}
//重新命名

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)){ //匹配檔案名稱

Rename_file_folder($path,$opath,$nname);//些函數下面講到

}else if( preg_match("/^\w{1,255}$/i",$nname,$temp_name) && preg_match("/^\w{1,255}$/i",$oname,$otemp_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";
}
}

}

上一篇

http://www.bkjia.com/PHPjc/631852.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631852.htmlTechArticle[原創]php+ajax實現類比Win檔案管理系統 // 本教程由本站原創,轉載請註明來處 作者:www.drise.cn 郵箱:drise@163.com QQ:271728967 // 就是deldir()函數了這...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.