- 论坛徽章:
- 0
|
想自己搭建个简易博客,对php不通,想通过/目录下index.php实现显示/日志目录下所有文与更新时间,并按照时间顺序排列,最好让其结果不要显示文件名后缀,并创建所有文件的连接。index.php应该如何写呢?望前辈支招!
这个是从网上找的一个代码,可以显示当前目录下所有文件,但没有时间排序。那位前辈帮忙改下吧。- <?php
- /* 函数 listDirTree( $dirName = null )
- ** 功能 列出目录下所有文件及子目录
- ** 参数 $dirName 目录名称
- ** 返回 目录结构数组 false为失败
- */
- function listDirTree( $dirName = null )
- {
- if( empty( $dirName ) )
- exit( "IBFileSystem: directory is empty." );
- if( is_dir( $dirName ) )
- {
- if( $dh = opendir( $dirName ) )
- {
- $tree = array();
- while( ( $file = readdir( $dh ) ) !== false )
- {
- if( $file != "." && $file != ".." && $file != "index.php" )
- {
- $filePath = $dirName . "/" . $file;
- if( is_dir( $filePath ) ) //为目录,递归
- {
- $tree[$file] = listDirTree( $filePath );
- }
- else //为文件,添加到当前数组
- {
- $tree[] = $file;
- }
- }
- }
- closedir( $dh );
- }
- else
- {
- exit( "IBFileSystem: can not open directory $dirName.");
- }
- //返回当前的$tree
- return $tree;
- }
- else
- {
- exit( "IBFileSystem: $dirName is not a directory.");
- }
- }
- $files = listDirTree(".");
- //print_r($files);
- $size = count(files);
- echo '<ol>';
- for( $i=0; $files[$i] != NULL; $i++ ) {
- echo '<li><a href="'.($files[$i]).'" target="_blank">'.$files[$i].'</a></li>';
- }
- echo '</ol>';
- ?>
复制代码 |
|