我不知道这是多么简单,但我使用的脚本显示来自特定文件夹的文件,但是我希望它们按字母顺序显示,难以做到这一点吗?下面是我使用的代码:它默认的字母顺序排列PHP(文件夹)按字母顺序排列的文件列表?
if ($handle = opendir($mainframe->getCfg('absolute_path') ."/images/store/")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (($file != "index.html")&&($file != "index.php")&&($file != "Thumbs.db")) {
$strExt = end(explode(".", $file));
if ($strExt == 'jpg') {
$Link = 'index.php?option=com_shop&task=deleteFile&file[]='.$file;
$thelist .= '<tr class="row0"><td nowrap="nowrap"><a href="'.$Link.'">'.$file.'</a></td>'."\n";
$thelist .= '<td align="center" class="order"><a href="'.$Link.'" title="delete"><img src="/administrator/images/publish_x.png" width="16" height="16" alt="delete"></a></td></tr>'."\n";
}
}
}
}
closedir($handle);
}
echo $thelist;
:)
啊,这是真棒作品像一个魅力,非常感谢你:D – SoulieBaby 2009-07-08 01:23:26
找到这个答案,同时试图解决同样的确切问题。谢谢!工作得很好,代码少! – Agos 2010-05-23 22:30:19
这很好。阅读完文档后,我甚至可以用`SCANDIR_SORT_DESCENDING`作为“scandir(...)`的第二个参数来反转排序顺序。在提供的链接中也记录了其他几个排序常量。 – 2015-04-15 02:30:27