is_dir() Problems

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
neridaj
Forum Commoner
Posts: 40
Joined: Fri Jan 05, 2007 9:55 pm

is_dir() Problems

Post by neridaj »

Hello,

I'm trying to use is_dir() to print a table of directories contained in a user directory. I want to skip the ./../ directories, which works as it should, and print the "valid directories" to the page as links but when I have say... three directories to output as links, I only get two of them, and they are all the same link i.e., directory. Also, the table cell containing the name of the directory is not output. I'm new to is_dir(), so if you can offer any help I would really appreciate it.

Code: Select all

function display_folders()
{
    $userfolder =  $_SESSION['valid_user'] . '/';
    echo '<table border="1" cellpadding="5">';
    $dir    = 'members/' . $userfolder;
    $files = scandir($dir);
    
    foreach($files as $value) {
    if(in_array($value, array('.', '..'))) { continue; }
    
        // check for folders
        if(is_dir($dir.DIRECTORY_SEPARATOR.$value)) {
            printf('<tr><td><a href="photos.php?pa=%s">'.
                    '<img src="images/files.gif" width=75" height="75 />'.
                   '<a/></td><td>%s</td></tr>',
                   $value, $value);
        }
    }
    echo '</table>';
}
 
Thanks,

Jason
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: is_dir() Problems

Post by yacahuma »

did you check php.net? there seems to be a lot of examples of exactly that.
Post Reply