Q: file name listing from directory including folders and subfolders i want to list out all files in a directory wallpaper/. there are more than 1000 folders inside this directory which are mainly celebrity name like angelina joulie etc and inside that folder several images are there for that celebrity.
i want to list all files with total path 
like http://xyz.com/wallpaper/angelina joulie/angeli1243.jpg
i tried scandir() readdir() glob() but all lists only current directory.
please tell how to list all files full path including subdirectory of a given directory

A: You need a recursive function. Here is a sample function that's tested and working properly.
function recursiveReaddir($folderPath = '.')
{
    $ignore = array('cgi-bin', '.', '..');
    $handle = @opendir($folderPath);
    while (false !== ($file = readdir($handle))) {

        if (!in_array($file, $ignore)) {
            if (is_dir("$folderPath/$file")) {
                $return[$file] = recursiveReaddir("$folderPath/$file");
            } else {
                $return [] = $file;
            }
        }
    }

    closedir($handle);
    return $return;
}
$rez = recursiveReaddir('path/to/file');
print_r($rez);


A: If you only need to go two levels in, it would be far easier to use glob():
glob("wallpaper/*/*")

Will traverse all immediate directories underneath wallpaper/.
