Site icon Bytefreaks.net

Simple PHP script that lists all files in a directory, sorts them by modification date, and creates hyperlinks for each

Advertisements
<?php

echo '<html>';

$ignore = array('.', '..', 'index.php');
$files = array();

foreach (scandir($dir) as $file) {
  if (in_array($file, $ignore)) {
    continue;
  }
  $files[$file] = filemtime($dir . '/' . $file);
}

arsort($files);

$keys = array_keys($files);

foreach ($files as $key => $value) {
  echo date('r', $value), ' <a href="', $dir, '/', $key, '">', $key, '</a><br/>';
}

echo 'Done';

echo '</html>';
?>

This post is also available in: Greek

Exit mobile version