发表于 2017-03-01 09:03:15 by 月小升
php遍历文件夹,不少时候还是很需要的
/*获取所有文件*/
function get_all_files( $path ){
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files( $item ) );
}
else{
$list[] = $item;
}
}
return $list;
} |
function get_all_files( $path ){
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files( $item ) );
}
else{
$list[] = $item;
}
}
return $list;
}
/*获取所有文件,只要一层目录文件*/
function get_my_files( $path ){
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list[] = $item;
}
}
return $list;
} |
function get_my_files( $path ){
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list[] = $item;
}
}
return $list;
}
php遍历文件夹加强版
/*获取所有文件,带时间*/
function get_all_files_time( $path ){
clearstatcache();
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files_time( $item ) );
}
else{
$list[$item] = ftime(fileatime($item)); //fileatime 访问时间 fileatime 访问时间 filemtime 修改时间
}
}
return $list;
} |
function get_all_files_time( $path ){
clearstatcache();
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files_time( $item ) );
}
else{
$list[$item] = ftime(fileatime($item)); //fileatime 访问时间 fileatime 访问时间 filemtime 修改时间
}
}
return $list;
}
/*获取所有文件,带时间*/
function get_all_files_mtime( $path ){
clearstatcache();
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files_mtime( $item ) );
}
else{
$list[$item] = ftime(filemtime($item)); //fileatime 访问时间 fileatime 访问时间 filemtime 修改时间
}
}
return $list;
} |
function get_all_files_mtime( $path ){
clearstatcache();
$list = array();
foreach( glob( $path . '/*') as $item ){
if( is_dir( $item ) ){
$list = array_merge( $list , get_all_files_mtime( $item ) );
}
else{
$list[$item] = ftime(filemtime($item)); //fileatime 访问时间 fileatime 访问时间 filemtime 修改时间
}
}
return $list;
}
This entry was posted in
PHP and tagged
php,
文件夹,
遍历. Bookmark the
permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:
月小升博客 –
https://java-er.com/blog/php-each-dir-4-way/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.