【发布时间】:2010-08-04 19:37:10
【问题描述】:
我正在尝试以与上次修改时间相反的顺序显示图像。不幸的是, get_headers() 似乎只适用于 url,而 stat['mtime'] 和 filemtime() 对我来说都失败了。我还有其他方法可以获取文件的最后修改信息吗?这是我目前的代码:
if (isset($_GET['start']) && "true" === $_GET['start'])
{
$images = array();
if ($dir = dir('images'))
{
$count = 0;
while(false !== ($file = $dir->read()))
{
if (!is_dir($file) && $file !== '.' && $file !== '..' && (substr($file, -3) === 'jpg' || substr($file, -3) === 'png' || substr($file, -3) === 'gif'))
{
$lastModified = filemtime($file);
$images[$lastModified] = $file;
++$count;
}
}
echo json_encode($images);
}
else { echo "Could not open directory"; }
}
【问题讨论】:
-
$count 变量是我之前成功的测试的残余,看看我是否至少可以检索文件名。
标签: php last-modified