PHP readir results - trying to sort by date created and also get rid of "." and ".." -


i have double question. part one: i've pulled nice list of pdf files directory , have appended file called download.php "href" link pdf files don't try open web page (they save/save instead). trouble need order pdf files/links date created. i've tried lots of variations nothing seems work! script below. i'd rid of "." , ".." directory dots! ideas on how achieve of that. individually, these problems have been solved before, not appended download.php scenario :)

<?php  $dir="../uploads2"; // directory files stored   if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false)   { ?> <p><a href="http://www.duncton.org/download.php?file=login/uploads2/<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php   } closedir($dir_list); }  ?> 

while can filter them out*, . , .. handles always come first. cut them away. in particular if use simpler scandir() method:

foreach (array_slice(scandir($dir), 2) $filename) { 

one use glob("dir/*") skips dotfiles implicitly. returns full path sorting ctime becomes easier well:

$files = glob("dir/*");  // make filename->ctime mapping $files = array_combine($files, array_map("filectime", $files));  // sorts filename list arsort($files); $files = array_keys($files); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -