Monday, September 23, 2019

PHP: list all files and sub-directories under the current directory


Create a file index.php:

<?php
$allItems = scandir(".");
$toHide = array('.', '..', 'index.php');
$toShow = array_diff($allItems, $toHide);

foreach ($toShow as $oneItem) {
    echo "<a href='$oneItem'>$oneItem</a><br>";
}
?>


No comments:

 
Get This <