日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

php 目錄遍歷、刪除 函數的使用介紹_PHP教程

編輯Tag賺U幣

推薦:php無限極分類實現(xiàn)的兩種解決方法
本篇文章介紹了,在php中無限極分類實現(xiàn)的兩種解決方法。需要的朋友參考下

小編今天沒事寫了目錄想關的函數

包括 遍歷該文件夾下的文件,目錄子目錄 讀取當前文件下目錄和文件 刪除當前文件夾下的目錄子目錄以及文件 以上三個函數目前還不支持中文文件 中文目錄

復制代碼 代碼如下:www.hl5o.cn

<?php
header("Content-type:text/html;charset=utf-8");
/**
* 讀取當前目錄下的文件和目錄
*
* @param string $path 路徑
* @return array 所有滿足條件的文件
*/
function tlist($path){
$path = iconv('utf-8', 'gbk', $path);
if(!is_dir($path)){
throw new Exception($path."不是目錄");
}
$arr = array('dir'=>array(),'file'=>array());
$hd = opendir($path);
while(($file = readdir($hd))!==false){
if($file=="."||$file=="..") {continue;}
if(is_dir($path."/".$file)){
$arr['dir'][] = iconv('gbk','utf-8',$file);
}else if(is_file($path."/".$file)){
$arr['file'][] = iconv('gbk','utf-8',$file);
}
}
closedir($hd);
echo "目錄有:".implode("<br />",$arr['dir'])."<br />";
echo "文件有:".implode("<br />",$arr['file']);
}
/**
* 遍歷當前目錄下的文件和目錄以及子文件夾中目錄
*
* @param string $path 路徑
* @return array 所有滿足條件的文件
*/
function blist($path){
if(!is_dir(iconv("utf-8","gbk",$path))){
throw new Exception("文件夾".$path."不存在或者不是文件");
}
$arr = array();
$hd = opendir(iconv("utf-8","gbk",$path));
while(($file = readdir($hd))!==false){
if($file=="."||$file=="..") {continue;}
$newpath=iconv('utf-8', 'gbk', $path) .'/'.$file;
if(is_dir($newpath)){
$arr[] = blist($path."/".$file);
}else if(is_file($newpath)){
$arr[] = iconv('gbk','utf-8',$file);
}
}
closedir($hd);
return $arr;
}
/**
* 刪除目錄下的文件以及子目錄
* #param string $path 路徑
* #return string 刪除成功返回true 失敗返回false;
*/
function dirDel($path){
if(!is_dir($path)){
throw new Exception($path."輸入的不是有效目錄");
}
$hand = opendir($path);
while(($file = readdir($hand))!==false){
if($file=="."||$file=="..") continue;
if(is_dir($path."/".$file)){
dirDel($path."/".$file);
}else{
@unlink($path."/".$file);
}

}
closedir($hand);
@rmdir($path);
}
?>

分享:基于php偽靜態(tài)的實現(xiàn)詳細介紹
本篇文章介紹了,基于php偽靜態(tài)的實現(xiàn)詳細分析。需要的朋友參考下

來源:模板無憂//所屬分類:PHP教程/更新時間:2013-04-29
相關PHP教程