# PHP directory reading. isdir(); isfile();

**URL:** https://forum.kirupa.com/t/php-directory-reading-isdir-isfile/219206
**Category:** programming
**Created:** [March 14, 2007, 6:38pm UTC](https://forum.kirupa.com/t/php-directory-reading-isdir-isfile/219206 "2007-03-14T18:38:57Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Limitlis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/limitlis/32/788_2.png) [@Limitlis](https://forum.kirupa.com/u/Limitlis)
#### Post date: [March 14, 2007, 6:38pm UTC](https://forum.kirupa.com/t/php-directory-reading-isdir-isfile/219206/1 "2007-03-14T18:38:57Z")

</div>

Hey all,  
I was hopeing that someone who has experience in this could help me out…

Im creating a web gallery for someone and am trying to make it folder based.

so each folder = an album essentially.

My first issue is that PHP readdir’s functions are acting weird.

first of all.

using something simple like this:

```auto

if ($handle = opendir("$directory")) {

   while (false !== ($file = readdir($handle))) {
      
                   echo "file type:".filetype($file)."<br />
";
                   echo "<a href=\"gallery.php?album=".$_GET['album']."/".$file."\">".$file."</a><br />
";

   }
   closedir($handle);
}

```

…to basically echo something like this.  
file type: dir  
foldername

OK. It works for the two folders “.” and “…” but not for any of the folders that i create myself!:fight: is there something that I’m missing?

My goal is to have one file gallery.php and append the name of the gallery as a $\_GET[] variable.

so folder/album summervacation = gallery.php?album=summervacation  
etc…

I have the directory reading working fine depending on the get variable.

I just need to find a way to detect folders.

I was thinking of maybe checking to see if theres an extension and if there isnt then it must be a folder… Still thinking about it.

Any help would be appreciated.

Thanks,  
Cesar
