【发布时间】:2014-03-10 07:15:13
【问题描述】:
我有一个从目录中检索文件的脚本,需要按日期对文件进行排序。最新照片上传到列表顶部。请给任何人建议?
<?
$slozka = "./gallery/holiday/"; //select the folder from which you want to list files
$thumb= "thumb"; //the name of the folder thumbnails
$vypis = opendir($slozka); //open folder
$celkem = '0'; //beginning number of photos
while (false!==($file = readdir($vypis))) //reading files
{
if($file!="."&&$file!=".."&&!is_dir($file)&&$file!=$thumb) //search through folder
{
$celkem++; //count the number of pictures
$filetitle = $file;
$nahrada = array("_", ".jpg", ".png", ".gif");
$filetitle = str_replace($nahrada, " ", "$filetitle");
if (file_exists($slozka.$thumb.'/'.$file))
{ //If there is a preview and display it ..
echo "<li><a href=\"gallery/holiday/".$file."\" alt=\"".$file."\"
title=\"".$filetitle."\" class=\"holiday\" /><img src=\"gallery/holiday/thumb/".$file."\" alt=\"".$file."\"></a><span class=\"nazvy\">".$filetitle."</span></li>";
}//If there is no way it will create ...
else
echo "<li><a href=\"gallery/holiday/".$file."\" alt=\"".$file."\" class=\"holiday\" /><img src=\"thumb.php?nazev=".$file."&cesta=".$slozka."\" alt=\"".$file."\"></a><span class=\"nazvy\">".$filetitle."</span></li>";
}
}
echo "</ul><div id=\"soucet\">Celkem fotek : ".$celkem."</div>"; // print the number of photos in the gallery ...
closedir($vypis); //close folder
?>
【问题讨论】: