PHP opendir(), sorting by date -


i have script retrieves files directory , need sort files date. latest photos uploaded top of list. please advise anyone?

<? $slozka = "./gallery/holiday/"; //select folder want list files $thumb= "thumb"; //the name of 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 number of pictures         $filetitle = $file;         $nahrada = array("_", ".jpg", ".png", ".gif");         $filetitle = str_replace($nahrada, " ", "$filetitle");          if (file_exists($slozka.$thumb.'/'.$file))         { //if there preview , display ..             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 no way create ...         else              echo "<li><a href=\"gallery/holiday/".$file."\" alt=\"".$file."\" class=\"holiday\" /><img src=\"thumb.php?nazev=".$file."&amp;cesta=".$slozka."\" alt=\"".$file."\"></a><span class=\"nazvy\">".$filetitle."</span></li>";     }  }      echo "</ul><div id=\"soucet\">celkem fotek : ".$celkem."</div>"; // print number of photos in gallery ... closedir($vypis); //close folder ?> 

you can use terminal command find function latest file directory. sort reverse , loop directory file pattern checking. latest file date.

check link reference.

https://superuser.com/questions/294161/unix-linux-find-and-sort-by-date-modified

ex :  find . -type f -name '{$fileformat}*'.txt -exec ls -tr {} \; | sort -r | head -10 $output = array(); @chdir($destinationdir); @exec($command, $output); 

then loop $output.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -