PHP文件目录操作问题 列出目录下的东西时 如何先列目录,再列文件 文件也按照名称或时间排序或者类型

来源:互联网 发布:淘宝买bb枪会有事吗 编辑:程序博客网 时间:2024/06/05 17:54
<script type="text/javascript"><!--google_ad_client = "pub-4490194096475053";/* 内容页,300x250,第一屏 */google_ad_slot = "3685991503";google_ad_width = 300;google_ad_height = 250;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<?php 
$ar = array(); 

$d = dir("."); 
while($f = $d->read()) { 
$ar['name'][] = $f; 
$ar['type'][] = is_dir($f) ? "dir" : "file"; 
$ar['time'][] = date("Y-m-d H:i:s",filectime($f)); 
$ar['size'][] = filesize($f); 

$d->close(); 

array_multisort($ar['type'],$ar['name'],SORT_STRING,SORT_ASC,$ar['time'],SORT_DESC,$ar['size']); 

echo "<table>"; 
foreach($ar['name'] as $k=>$v) 
printf("<tr><td>%s</td><td>%s</td><td>%d</td><td>%s</td></tr>",$v,$ar['type'][$k]=="dir"?"[DIR]":"",$ar['size'][$k],$ar['time'][$k]); 
echo "</table>"; 
?> 

返回结果如下: 

. [DIR] 0 2004-08-16 09:13:51 
.. [DIR] 0 2004-07-29 15:27:34 
admin [DIR] 0 2004-08-16 09:13:51 
db [DIR] 0 2004-08-16 09:13:51 
includes [DIR] 0 2004-08-16 09:13:51 
install [DIR] 0 2004-08-16 09:13:52 
language [DIR] 0 2004-08-16 09:13:52 
templates [DIR] 0 2004-08-16 09:13:52 
admin_login.php 7765 2004-08-16 09:13:51 
common.php 4099 2004-08-16 09:13:51 
config.php 259 2004-08-16 09:28:24 
extension.inc 757 2004-08-16 09:13:51 
redme.doc 10752 2004-08-16 09:13:52 
test.php 907 2004-08-16 09:13:52 
test2.php 338 2004-09-22 15:10:00 
设计说明文档.txt 369 2004-08-16 09:13:52
原创粉丝点击