August 15, 2022


The complete guide to the beginners as well as to the experienced Web Developers

Directories, subdirectories with all files – PHP

Here is a simple PHP function to list all files in directories. This is a recursive function so it will list files of all of its subdirectories too. PHP default function scandir() gave the only list of folders and files, it does not give the list of inside directory.

The solution for listing all the folders, subfolders, files in a directory using PHP.

This is a recursive function recursive so when used for any framework where you need just check for the call function.

for ex. codeigniter framework -controller class then you need just changeget_all_directory_and_files(“$dir/$item”); to $this->get_all_directory_and_files(“$dir/$item”);


../demo2/images/Sorting icons.psd