PHP list all files in directory


 

PHP list all files in directory

In this tutorial we will learn to list all the files and directories in the given directory name.

In this tutorial we will learn to list all the files and directories in the given directory name.

  • Using the readdir() and opendir() function all files of the directory can be listed.
  • readdir() function uses the file handler of the readdir() function.
  • It then returns the filename of the directory.


Example

<?php
    $file
=opendir("c:/apache-tomcat-6.0.16");
     while
($a=readdir($file))
       {
        echo
$a."<br>";
       }
?>

Output
.
..
bin
conf
lib
LICENSE
logs
NOTICE
RELEASE-NOTES
RUNNING.txt
spring1.war
temp
webapps
work

Ads