Answers for "read all files in decending order of timestamp php"

PHP
1

php sort file names by date

<?php
// get current directory path
$dirpath = getcwd();
// set file pattern
$dirpath .= "\*.jpg";
// copy filenames to array
$files = array();
$files = glob($dirpath);

// sort files by last modified date
usort($files, function($x, $y) {
    return filemtime($x) < filemtime($y);
});

foreach($files as $item){
    echo basename($item) . " => Last Modified On " . @date('F d, Y, H:i:s', filemtime($item)) . "<br/>";
}
?>
Posted by: Guest on August-27-2020
0

php list directory files by date

function listdir_by_date($path){

  $ar = [];
  chdir($path);
  array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files);
  foreach($files as $filename)
  {
    $ar[] = $filename;
  }

  return $ar;
}
Posted by: Guest on August-26-2020

Code answers related to "read all files in decending order of timestamp php"

Browse Popular Code Answers by Language