View Full Version : Advanced directory listing?

03-21-2003, 09:42 AM
Hi there,

I can do a basic directory listing. But what I would like is to be able to use the result; for example, display all images in a directory, or create links to all files.

I've tried to do this using str_replace() {as it's one of half a dozen functions I actually know :o} but I have a problem with three dots messing things up ... So I'm thinking surely there's a better way?


03-21-2003, 09:46 AM
this might be relevant


//define the path as relative
$path = ".";

//open directory for list
$dir_handle = @opendir($path) or die("Unable to open $path");

//print filenames
print "<pre>";
while ($file = readdir($dir_handle)) {
//if filename contains .shtml or .phtml
if(ereg("\.[sp]html",$file) {

print "<a href=\"$file\">$file</a>\n";

//close directory
print "</pre>";


03-21-2003, 10:28 AM
That works, well it doesn't with the [sp] bit in place but there's ways around for multiple file types...

03-21-2003, 10:50 AM
"insert regex here", innit :)