how to fetch all files from folder using php

PHP directory listing

Some times we have to display the list of all files in a directory.We can do this with the help of php function readdir(). The code to display all the files is given blow.

$path=’images/’;// change the path here related to this page

$handle=opendir($path);

while (($file = readdir($handle))!==false)

{

if(strlen($file)>3)

{

echo “<img src=$path$file> <br>”;

}

}

closedir($handle);

Share This Post

Post Comment