使用PHP获取目录中文件的最后修改日期 [英] Getting last modification date of files in directory using PHP
本文介绍了使用PHP获取目录中文件的最后修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用PHP获取目录中所有文件的最后修改日期。
I am trying to get the last modification date of all files in a directory using PHP.
我使用的是:
foreach($dir as $file)
{
$mod_date=date("F d Y H:i:s.", filemtime($file));
}
foreach($ dir as $ file) code>正在返回正确的文件,但所有修改日期将以0000-00-00 00:00:00为准,而不是实际的修改日期。
foreach($dir as $file)
is returning the correct files, but all of the modification dates are coming back as 0000-00-00 00:00:00, instead of the actual modification date.
需要做哪些更改才能使其正常工作?
What changes do I need to make to get this working?
推荐答案
检查$ file var是否实际指向正确的文件
Check if the $file var is actually pointing to a correct file
foreach($dir as $file)
{
if(is_file($file))
{
$mod_date=date("F d Y H:i:s.", filemtime($file));
echo "<br>$file last modified on ". $mod_date;
}
else
{
echo "<br>$file is not a correct file";
}
}
这篇关于使用PHP获取目录中文件的最后修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文