標籤:style blog color io os ar sp 檔案 div
1 <?php 2 header("Content-type:text/html;charset=utf-8"); 3 4 /** 5 * getDirFile 遍曆檔案夾中的所有檔案 6 * @param $path 7 */ 8 function getDirFile($path){ 9 //判斷是否是檔案夾10 if(is_dir($path)){11 //判斷是否開啟成功12 if($handle = opendir($path)){13 14 //讀取檔案15 while($file = readdir($handle)){16 //判斷是否是檔案夾17 if(is_dir($path.‘/‘.$file) && $file != ‘.‘ && $file != ‘..‘){18 echo ‘檔案夾:‘.$file.‘<br/>‘;19 getDirFile($path.‘/‘.$file);20 } else {21 if($file != ‘.‘ && $file != ‘..‘){22 echo ‘檔案:‘.$file.‘<br/>‘;23 }24 }25 }26 27 //關閉檔案夾28 closedir($handle);29 }30 }31 }
1 /** 2 * removeDir 刪除檔案夾下所有檔案 3 * @param $path 4 */ 5 function removeDir($path){ 6 //判斷是否是檔案夾 7 if(is_dir($path)){ 8 //判斷是否開啟成功 9 if($handle = opendir($path)){10 //讀取檔案11 while($file = readdir($handle)){12 //判斷是否是檔案夾13 if(is_dir($path.‘/‘.$file.‘/‘) && $file!=‘.‘ && $file!=‘..‘){14 removeDir($path.‘/‘.$file.‘/‘);15 } else {16 if($file!=‘.‘ && $file!=‘..‘){17 //刪除檔案18 unlink($path.‘/‘.$file);19 }20 }21 22 }23 //關閉檔案夾24 closedir($handle);25 //刪除檔案夾26 rmdir($path.‘/‘.$file.‘/‘);27 }28 }29 }
PHP遍曆、刪除檔案夾中的所有檔案