function to grab file name from a folder
Posted: Sun Feb 12, 2006 5:23 am
Im looking for a function or a way to grab all the file names in a certain folder and chuck them into an array, does any one know how to do this.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$directory = "directory1"; // directory name
$dir = opendir($directory);
while(($file = readdir($dir)))
{
if(is_file($directory.'/'.$file))
{
$a[] = $file;
}
} // end while
closedir($dir);
// $a containes all the file names in the direstory
echo "<pre>"; print_r($a); echo "</pre>";