我不确定这有多简单,但我正在使用一个显示特定文件夹中的文件的脚本,但是我希望它们按字母顺序显示,这样做会很难吗?这是我正在使用的代码:
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;
:)
而不是使用readdir
你可以简单地使用scandir
(文档) 默认情况下按字母顺序排序。
返回值scandir
是一个数组而不是字符串,因此您的代码必须稍微调整,以迭代数组而不是检查最终的null
返回值。还,scandir
采用带有目录路径的字符串而不是文件句柄作为输入,新版本将如下所示:
foreach(scandir($mainframe->getCfg( 'absolute_path' ) ."/images/store/") as $file) {
// rest of the loop could remain unchanged
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)