PHP遍歷某個目錄下的所有文件和子文件夾的實現代碼
更新時間:2013年06月28日 14:54:10 作者:
本篇文章是對PHP遍歷某個目錄下的所有文件和子文件夾的實現代碼進行了詳細的分析介紹,需要的朋友參考下
復制代碼 代碼如下:
<?php
function read_all_dir ( $dir )
{
$result = array();
$handle = opendir($dir);
if ( $handle )
{
while ( ( $file = readdir ( $handle ) ) !== false )
{
if ( $file != '.' && $file != '..')
{
$cur_path = $dir . DIRECTORY_SEPARATOR . $file;
if ( is_dir ( $cur_path ) )
{
$result['dir'][$cur_path] = read_all_dir ( $cur_path );
}
else
{
$result['file'][] = $cur_path;
}
}
}
closedir($handle);
}
return $result;
}
?>
相關文章
PHP實現從PostgreSQL數據庫檢索數據分頁顯示及根據條件查找數據示例
這篇文章主要介紹了PHP實現從PostgreSQL數據庫檢索數據分頁顯示及根據條件查找數據操作,涉及PHP操作PostgreSQL數據庫的SQL條件查詢、分頁、顯示等相關操作技巧,需要的朋友可以參考下2018-06-06

