I want to read a list the names of files in a folder in a web page using php. is there any simple script to acheive it?
+9
A:
The simplest and most fun way (imo) is glob
foreach (glob("*.*") as $filename) {
echo $filename."<br />";
}
But the standard way is to use the directory functions.
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: ."$file."<br />";
}
closedir($dh);
}
}
There are also the SPL DirectoryIterator methods. If you are interested
Ólafur Waage
2009-04-06 09:20:26
Thanks Olafur that helps a lot..
Smart Pandian
2009-04-11 07:03:48