List directory files (PHP)

by spyka (http://www.spyka.net)

Lists the files inside a given directory
Just change the path to the folder you want to list files out of

Code:
<?php 
if ($handle opendir('/path/to/files')) { 
    echo 
"Directory handle: $handle\n"
    echo 
"Files:\n"

    
// List all the files 
    
while (false !== ($file readdir($handle))) { 
        echo 
"$file\n"
    } 

    
closedir($handle); 

?> 

Code demo

List directory files online demo

Help and comments

Discuss this and other scripts in our webmaster foruns

Learn more about our forums