2011-02-07 164 views
-1

我發現了一個腳本來達到目的,但我需要修改它來回顯服務器端文件的實際時間/日期戳。Echo文件的時間和日期(PHP)

基本上這個腳本掃描稱爲「上傳」目錄,並在頁面上顯示該文件夾的名稱(在H3)和任何文件(在)包含在他們的鏈接(一個)到相應的文件。但是,除了文件名外,我還希望顯示實際文件的時間/日期戳(注意我沒有在數據庫中存儲任何信息)。這裏是腳本:

<?php 
function ls_recursive($dir) { 
    if(is_dir($dir)) { 
    $files = scandir($dir); 
    foreach ($files as $file) { 
    $currentfile = $dir."/".$file; 
    $last_dir = ""; 
    $count = substr_count($currentfile, '/'); 
    $minus_count = substr_count($_SERVER['DOCUMENT_ROOT'], '/'); 
    $count -= ($minus_count + 2); 

    for($p = 0; $p<$count; $p++) { 
    $last_dir .= ""; 
} 

    if(is_dir($currentfile)) { 
    if($file != '.' && $file != '..') { 
    $last_dir = "<h3 class='topic'>" . substr($currentfile, strrpos($currentfile, '/')+1) . "</h3>\n"; 
    echo $last_dir; 
    echo "<ul class=\"files info\">\n"; 
    ls_recursive($currentfile); 
    } 
} 
    else { 

    $last_dir = "<li><a href=\"".$currentfile."\">".substr($currentfile, strrpos($currentfile, '/')+1)."</a></li>\n"; 
    echo $last_dir; 


    } 

    } 
    } 
    echo "</ul>\n"; 
    echo "<div class='clear'></div>"; 
} 

ls_recursive('uploads'); 
?> 

我正在運行PHP5。任何建議,將不勝感激。

在此先感謝。

+0

filectime()+日期()。對於這個建議是否夠用,或者你需要完整的代碼? – 2011-02-07 10:56:49

回答

4

echo "Last modified: " . date ("F d Y H:i:s.", filemtime($filename)); 
+0

輝煌。工作過一種享受。謝謝! – PHPnoob 2011-02-07 11:05:00

0

http://www.php.net/manual/en/book.filesystem.php

> /* Get file stat */ $stat = 
> stat('C:\php\php.exe'); 
> 
> /* * Print file access time, this is 
> the same * as calling fileatime() 
> */ echo 'Access time: ' . $stat['atime']; 
> 
> /* * Print file modification time, 
> this is the * same as calling 
> filemtime() */ echo 'Modification 
> time: ' . $stat['mtime'];