[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 編程技術 > Php > 正文
PHP源碼學習:將目錄下的文件按照上傳/修改的最近時間排序
本文出自:http://php2000.com/~uchinaboy/wdb/wdb.php 作者: uchinaboy (2001-12-01 17:52:59)


一個給目錄下的文件(按照上傳/修改的最近時間)排序的程序…… 
有一個白痴的地方,忘了用全局數組,不過沒關系…… 

<?php 
/****************************************************  
program : Spr2[timeorder_txt]  
Author  : uchinaboy   
E-mail  : uchinaboy@163.com  
QQ      : 16863798  
Date    : 2001-8-7 
****************************************************/ 
function judge($i, $filename, $time, $m) { 
if ($i == $m) { 
while(list($key, $value)= each($filename)) { 
$filename[$key] = $value; //echo $filename[$key]."<br>"; 

while(list($key, $value) = each($time)) { $time[$key] = $value; //echo $time[$key]."<BR>";  } 

for ($j = 0; $j < $i; $j++) { 
if ($time[$j] > $max) { 
$max = $time[$j]; 
$sign = $j; 

if ($j == ($i-1)) { 
echo $filename[$sign]." Ê±¼äÖµ£º".$time [$sign]."<br>"; 
if($sign < $j) { $time[$sign] = $time[$j]; 
$filename[$sign] = $filename[$j]; 

judge($i-1, $filename, $time, $m); 


}  

function list_file($path, $mode = 1) {  
$handle = opendir($path); 
while ($file = readdir($handle)) { 
$length = strpos($file, "."); 
if ($length) { static $i = 0; 
$time[$i] = fileatime($file); 
$filename[$i] = $file; //echo $filename[$i].$time[$i]."<BR>"; $i++; 

} $m = $i; 
judge($i, $filename, $time, $m);  
}  
list_file("."); 

?>
 

(http://www.fanqiang.com)
    進入【UNIX論壇

相關文章
 

★  樊強制作 歡迎分享  ★