您的位置:首页 > 编程语言 > PHP开发

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

2008-09-07 21:27 1001 查看
<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐