我有一个音频播放器,它从一个文件夹中提取音频,该文件夹当前正在按名称排序,但是我想按创建日期对其进行排序。任何帮助将不胜感激。
$media = array();
$di = new DirectoryIterator($dir);
foreach ($di as $fileinfo) {
$path_info = pathinfo($fileinfo->getPathname());
if(isset($path_info['extension'])){
if(in_array(strtolower($path_info['extension']), $allowed_files)){
$fn = $fileinfo->getPathname();
$media[] = array(
"SITE_URL" => SITE_URL,
"SITEPATH" => SITEPATH,
"fullpath" => SITE_URL.'/'.path2url(realpath($path_info['dirname'])).'/'.$path_info['basename'],
"basename" => $path_info['basename'],
"extension" => $path_info['extension'],
"dirname" => realpath($path_info['dirname']),
"filename" => $path_info['filename']
);
}
}
答案 0 :(得分:2)
DirectoryIterator
仅授予对access Time
,modification time
或inode change time
的访问权限。如果自创建以来文件没有更改,DOM
将相同,然后您可以将时间保存在modification time
数组中,然后使用array_multisort
对数组进行排序:
$media