I'm trying to get a listing of the subdirectories in a given folder - but for some reason the is_dir()-function only returns "." and ".." even though I know there are two subdirectories in the folder. The code I have is as follows: $img_folder = "images/"; $list_dir = scandir($img_folder); foreach ($list_dir as $value) { if (is_dir($value)) { var_dump($value); } } PHP: This outputs the following: string(1) "." string(2) ".." It should also list to other subdirectories, namely "medium" and "thumbs" - but it doesn't. If I try running the same code, but change the $img_folder variable to = "./" I get a full listing of the subdirectories in the root folder - so what am I doing wrong? It doesn't help adding "./" in front of the folder name either... it still just gives the "." and ".." - if I hadn't known there to be two folders, I would assume it listed an empty directory.
The names you get from scandir() are not fully-qualified paths. You need to add the path to your call to is_dir() - for example: is_dir("{$img_folder}{$value}") Code (markup): or else you will just be comparing a list of filenames from "images" against the contents of your script's current working directory. It is not surprising that the only overlap is "." and ".."