开发者

Getting last modified info from files with PHP when filemtime, stat['mtime'], and get_headers fail

I'm trying to display images in the reverse order of when they were last modified. Unfortunately, get_headers() seems to only work for urls, and开发者_运维问答 both stat['mtime'] and filemtime() fail for me. Are there any other ways for me to get the last modified info for a file? Here's my code at the moment:

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"; }
}


You should prepend the path to the filename, before calling filemtime($file). Try

$lastMod = filemtime("images/".$file);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜