【问题标题】:Sort Images by Date Modified按修改日期排序图像
【发布时间】:2016-10-31 12:37:03
【问题描述】:

我有一个小脚本,可以将文件夹中的图像放入网页。 我想按 DATE MODIFIED 排序,有人知道怎么做吗?

function php_thumbnails($imagefolder,$thumbfolder,$lightbox)
{
//Get image and thumbnail folder from function
$images = "portfolio/" . $imagefolder; //The folder that contains your images. This folder must contain ONLY ".jpg files"!
$thumbnails = "portfolio/" . $thumbfolder; // the folder that contains all created thumbnails.
//Load Images
//load images into an array and sort them alphabeticall:
$files = array();
if ($handle = opendir($images))
    {
    while (false !== ($file = readdir($handle)))
        {
        //Only do JPG's
        if(eregi("((.jpeg|.jpg)$)", $file))

            {
            $files[] = array("name" => $file);
            }
        }
    closedir($handle);
    }
//Obtain a list of columns

foreach ($files as $key => $row)
    {
    $name[$key]  = $row['name'];
    }
//Put images in order:
array_multisort($name, SORT_ASC, $files);
//set the GET variable name
$pic = $imagefolder;

【问题讨论】:

    标签: php sorting lightbox


    【解决方案1】:

    您需要使用filemtime 函数来检索文件修改时间,然后使用它来构建您的多排序帮助数组。

    ...
    if(eregi("((.jpeg|.jpg)$)", $file))
        {
        $datem = filemtime($images . '/' . $file);
        $files[] = array("name" => $file, "date" => $datem);
        }
    }
    ...
    ...
    ...
    foreach ($files as $key => $row)
    {
       $date[$key]  = $row['date'];
    }
    //Put images in order:
    array_multisort($date, SORT_ASC, $files);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-03
      相关资源
      最近更新 更多