SoFunction
Updated on 2025-03-10

How to display subdirectories in the specified directory

This article example describes the method of displaying subdirectories under specified directories in PHP. Share it for your reference. The specific implementation method is as follows:

<?php
echo "<h2>subdirs in dir</h2><ul>";
$basedir = basename( __FILE__ );
$dirtoscan = ($basedir . '/somedir/');
$albumlisting = scandir($dirtoscan);
foreach ($albumlisting as $item) {
  $dirinfo = pathinfo($item);
  print_r($dirinfo);
  if (is_dir("$item")) {
   echo "<li><a href='?subdirs=$item'>$item</a></li>";
  }
}
?>

I hope this article will be helpful to everyone's PHP programming.