【发布时间】:2014-12-02 00:56:53
【问题描述】:
<?php
$current_dir = "/members/downloads/board-meetings/2014/"; // Full path to directory
$dir = opendir($current_dir); // Open directory
echo ("");
while ($file = readdir($dir)) // while loop
{
$parts = explode(".", $file); // Pull apart the name and dissect by period
if (is_array($parts) && count($parts) > 1) {
$extension = end($parts); // Set to see last file extension
if ($extension == "pdf" OR $extension == "PDF") // PDF DOCS by extention
echo "<li class=\"pdf\"><strong><a href=\"/members/downloads/board-meetings /$file\" class=\"underline\" target=\"_blank\">$file</a></strong></li>"; // If so, echo it out!
}
}
echo "<br>";
closedir($dir); // Close the directory
?>
我希望向专家寻求帮助。这段代码很好用,只是这个站点需要按月列出文件名。它们被命名为:January.pdf、February.pdf 等......并且它们需要按月倒序排列。所以 December.pdf,然后是 November.pdf 等等......我得到:October.pdf November.pdf April.pdf - 离基地很远。任何想法都将不胜感激。
【问题讨论】:
-
你可以先将它们收集到一个数组中,然后在那里进行排序
标签: php sorting opendir readdir