Rate this script:  I Love it  /   I Hate it

PHP: Get file names from a specified directory


Code


$string="";
$fileCount=0;
$filePath=$PATH.'/var/www/public_html/'; # Specify the path you want to look in.
$dir = opendir($filePath); # Open the path
while ($file = readdir($dir)) {
  if (eregi("\.php",$file)) { # Look at only files with a .php extension
    $string .= "$file<br />";
    $fileCount++;
  }
}
if ($fileCount > 0) {
  echo sprintf("<strong>List of Files in %s</strong><br />%s<strong>Total Files: %s</strong>",$filePath,$string,$fileCount);
}
 

 

 
PHP: Get file names from a specified directory scripts | PHP: Get file names from a specified directory snippet | PHP: Get file names from a specified directory example | PHP: Get file names from a specified directory tutorial | PHP: Get file names from a specified directory code