Directory List - Strip Files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mad687
Forum Newbie
Posts: 2
Joined: Sat Apr 15, 2006 5:54 pm

Directory List - Strip Files

Post by mad687 »

I'm trying to create a script that lists out directories in a <select> dropdown. I've figured out how to list a complete directory (script below), but now I have to figure out how to remove all of the files (I only need the directories). Any tips?

Thanks,
Marcus

Code: Select all

<select>
<?
    $path = "/home/kinetici/public_html/pbluff/test single file/download/";
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)) {

    if($file == "." || $file == ".." || $file == "index.php" )

        continue;
        echo "<option value=\"$file\">$file</option>";

    }

    // Close
    closedir($dir_handle);

?>
</select>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mad687
Forum Newbie
Posts: 2
Joined: Sat Apr 15, 2006 5:54 pm

Worked! Thanks

Post by mad687 »

Ok thanks, that worked.

Just in case someone ever needs this code heres the working version:

Code: Select all

<select name="lot">
<?
    $path = "/home/kinetici/public_html/pbluff/test single file/download/";
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)) {

    if($file == "." || $file == ".." || $file == "index.php" || $file != is_dir($path . $file) )

        continue;
        echo "<option value=\"$file\">$file</option>";

    }

    // Close
    closedir($dir_handle);

?>
</select>
Post Reply