Thursday, 18 August 2011

How to List files of a Directory in php



You might require this code which lists all files from a specific directory in php. It shows the files from a folder you want.Even you can specify which files to ignore eg. when showing image you dont want to show thumbs.db file, so you can specify in the code neglect thumbs.db file.
So your code will show all files except thumbs.db 



<? php
$maindir = "." ; 
$mydir = opendir($maindir) ; 
$exclude = array("index.php","test.txt") ; 
while($fn = readdir($mydir)) 

if ($fn == $exclude[0] || $fn == $exclude[1]) continue; 
echo "
 \n <a href='$fn'>$fn</a>"; 

closedir($mydir); 
?>

No comments:

Post a Comment