PHP

HOW TO LIST FILES & FOLDERS IN PHP

1) SCANDIR

$contents = scandir("FOLDER"); print_r($contents);

2) GLOB

// GET ALL PHP + TEXT FILES $scripts = glob("FOLDER/*.{php,txt}", GLOB_BRACE); print_r($scripts);   // GET FOLDERS ONLY $folders = glob("FOLDER/*", GLOB_ONLYDIR); print_r($folders);

3) OPENDIR

$target = "FOLDER"; if ($fh = opendir($target)) {   while (($entry = readdir($fh)) !== false)   {     if ($entry!="." && $entry!="..")      { echo $entry; }   }   closedir($fh); }