首页 > 解决方案 > 在php中显示目录中所有文件的修改日期和时间

问题描述

我正在编写如下所示的 php 代码,我想在其中显示目录(outgoing_folder)中所有文件的修改日期和时间。

$destination = 'outgoing_folder';  
$mp3_files = preg_grep('/^([^.])/', scandir($destination)); /* Line#Z */
print_r($mp3_files);  /* Line#X */

Line#X打印以下内容:

Array ([2] => 36017P.mp3 [3] => 36031P.mp3 [4] => hello.mp3)

我 在Line#ALine#B处使用了Line#Z ,以便显示目录中所有文件的修改日期和时间。

<?php   foreach ($mp3_files as $file ) :  ?>  /* Line #A */
<tr>
   <td style="width:8%; text-align:center;"> <?php echo basename($file, ".mp3"); ?></td>
   <td style="width:8%; text-align:center;"><?php echo date("F d Y",filemtime("$file")); ?></td>   /* Line #B */
</tr>
<?php
   endforeach;
?>

Line#B显示以下 o/p(不是文件的修改日期和时间):

Date 
December 31 1969
December 31 1969
December 31 1969

问题陈述:

我想知道我需要在Line#B的 php 代码中进行哪些更改,以便能够检索目录中所有文件的修改日期和时间。

标签: phphtml-tablefilemtime

解决方案


推荐阅读