tags:

views:

296

answers:

1

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
Thanks Olafur that helps a lot..
Smart Pandian