Jump to content

Show directory listing, excluding sub-directories and only certain files by ext


monkeymynd

Recommended Posts

I must be brain dead...I've searched everywhere and can't seem to find a snippet for this. I'm just looking for some code to show a directory listing, but only certain files (by extension) and I don't want to show any sub-directories.

 

I thought I might have been able to do this in the .htaccess file, but I can't find anything that will get rid of the sub-directories.

 

So, I figure there must be a way to get a file listing, check the extension, add it to the page, or skip it if it's a sub-directory or doesn't match the extension.

 

Or, I could just be totally, way off...anyway, any help would be greatly appreciated...I'm fairly new to php.

This should get you started:

 

<?php
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.