2016-10-31 2 views
0

폴더의 이미지를 웹 페이지에 넣는 작은 스크립트가 있습니다. 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; 

답변

0

당신은 당신의 multisort 도움 배열을 구축 할 파일의 수정 시간을 검색 할 수 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);