11
08月
2015
21. 目录清单
使用下面的 PHP 代码片段可以在一个目录中列出所有文件和文件夹
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
function list_files( $dir )
{
if ( is_dir ( $dir ))
{
if ( $handle = opendir( $dir ))
{
while (( $file = readdir( $handle )) !== false)
{
if ( $file != "." && $file != ".." && $file != "Thumbs.db" /*pesky windows, images..*/ )
{
echo '<a target="_blank" href="' . $dir . $file . '">' . $file . '</a><br>' . "\n" ;
}
}
closedir ( $handle );
}
}
}
|
语法:
1
2
3
|
<?php
list_files( "images/" ); //This will list all files of images folder
?>
|
特殊说明,本文版权归 ning个人博客 所有带原创标签请勿转载,转载请注明出处.