我有一个脚本,它将文件从MySQL数据库导出为CSV文件。 我想创建一个链接以从目录中下载最新文件。 有没有办法用PHP做?
干杯
您可以比较该文件夹中所有文件的文件修改时间并获取最新的文件
$lastestFile = "";
$lastestTime = 0 ;
$path = "../";
foreach ( new DirectoryIterator ( $path ) as $file ) {
if ($file->getBasename () == "." || $file->getBasename () == "..")
continue;
if($lastestTime < $file->getMTime() )
{
$lastestTime = date("Y-m-d g:i:s",$file->getMTime());
$lastestFile = $file->getBasename();
}
}
var_dump($lastestFile,$lastestTime);
输出
string 'webservice' (length=10)
string '2012-04-19 11:15:50' (length=19)