December 2, 2022

WeAnswer

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”);

Result:

../demo2/css/jquery.dataTables.css
../demo2/employee-grid-data.php
../demo2/employee.sql
../demo2/images/back_disabled.png
../demo2/images/back_enabled.png
../demo2/images/back_enabled_hover.png
../demo2/images/favicon.ico
../demo2/images/forward_disabled.png
../demo2/images/forward_enabled.png
../demo2/images/forward_enabled_hover.png
../demo2/images/sort_asc.png
../demo2/images/sort_asc_disabled.png
../demo2/images/sort_both.png
../demo2/images/sort_desc.png
../demo2/images/sort_desc_disabled.png
../demo2/images/Sorting icons.psd
../demo2/index.php
../demo2/js/jquery.dataTables.js
../demo2/js/jquery.js