Home / PHP Tips Generated By ChatGPT / Generating a List of Files in a Directory in PHP Use scandir() to list all files and directories within a specified path. Source Code $files = scandir('path/to/directory'); foreach ($files as $file) { if (!in_array($file, array('.', '..'))) { echo $file . "n"; } }