代码之家  ›  专栏  ›  技术社区  ›  Major Productions

当filemtime、stat['mtime']和get\ headers失败时,使用PHP从文件获取上次修改的信息

  •  0
  • Major Productions  · 技术社区  · 14 年前

    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"; }
    }
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   mvds    14 年前

    在调用之前,应该预先设置文件名的路径 filemtime($file) . 尝试

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