-3
폴더에서 파일 이름을 정렬하는 방법 을 작성 날짜순으로 정렬 by php?PHP로 만든 날짜로 폴더 순서에서 파일 이름을 정렬하는 방법?
$filesname = dirname(__FILE__) . '/../tmp/20120123/';
foreach(glob($filesname) as $files){
echo $files.'<br />';
}
폴더에서 파일 이름을 정렬하는 방법 을 작성 날짜순으로 정렬 by php?PHP로 만든 날짜로 폴더 순서에서 파일 이름을 정렬하는 방법?
$filesname = dirname(__FILE__) . '/../tmp/20120123/';
foreach(glob($filesname) as $files){
echo $files.'<br />';
}
난 그냥 그런 작업을 위해 쓴이 기능을 사용해보십시오 :
// Constants to make usage more reader-friendly
define('DIR_SORT_NAME', 1);
define('DIR_SORT_SIZE', 2);
define('DIR_SORT_ATIME', 3);
define('DIR_SORT_MTIME', 4);
define('DIR_SORT_CTIME', 5);
function readdir_sorted_array ($dir, $sortCol = DIR_SORT_NAME, $sortDir = SORT_ASC) {
// Validate arguments
$dir = rtrim(str_replace('\\', '/', $dir), '/');
$sortCol = (int) ($sortCol >= 1 && $sortCol <= 5) ? $sortCol : 1;
$sortDir = ($sortDir == SORT_DESC) ? SORT_DESC : SORT_ASC;
$name = $size = $aTime = $mTime = $cTime = $table = array();
// Open the directory, return FALSE if we can't
if (!is_dir($dir) || (!$dp = opendir($dir))) return FALSE;
// Fetch a list of files in the directory and get stats
for ($i = 0; ($file = readdir($dp)) !== FALSE; $i++) {
if (!in_array($file, array('.','..'))) {
$path = "$dir/$file";
$row = array('name'=>$file,'size'=>filesize($path),'atime'=>fileatime($path),'mtime'=>filemtime($path),'ctime'=>filectime($path));
$name[$i] = $row['name'];
$size[$i] = $row['size'];
$aTime[$i] = $row['atime'];
$mTime[$i] = $row['mtime'];
$cTime[$i] = $row['ctime'];
$table[$i] = $row;
}
}
// Sort the results
switch ($sortCol) {
case DIR_SORT_NAME:
array_multisort($name, $sortDir, $table);
break;
case DIR_SORT_SIZE:
array_multisort($size, $sortDir, $name, SORT_ASC, $table);
break;
case DIR_SORT_ATIME:
array_multisort($aTime, $sortDir, $name, SORT_ASC, $table);
break;
case DIR_SORT_MTIME:
array_multisort($mTime, $sortDir, $name, SORT_ASC, $table);
break;
case DIR_SORT_CTIME:
array_multisort($cTime, $sortDir, $name, SORT_ASC, $table);
break;
}
// Return the result
return $table;
}
희망 사용량이 상당히 자기 설명이다.
[PHP의 날짜순 정렬 파일] 가능한 복제본 (http://stackoverflow.com/questions/2667065/sort-files-by-date-in-php) – Gordon
[File Creation Time] (http : //stackoverflow.com/questions/2084986/file-creation-time) – Gordon