Example:This example contains four PHP files (file1.php, file2.php, file3.php, file4.php) in a directory. Create one file called main.php that contains the PHP code to include the files.
Create file1.php in the myGeeks folder: php
echo
"1st File Included Successfully
"
;
?>
Create file2.php file in myGeeks folder ": < tbody> php
echo
"2nd File Included Successfully
"
;
?>
Create file3.php in myGeeks folder : php
echo
"3rd File Included Successfully
"
;
?>
Create file4.php file in myGeeks folder ": < tbody> php
echo
"4th File Included Successfully
"
;
?>
Create main.php outside the folder: php
foreach
(
glob
(
"folder / *. php "
)
as
$filename
) {
include
$filename
;
}
?>
Run on Windows platform: - The myGeeks folder, which contains all the files:
- The htdocs folder contains the main.php file:
- Run in browser:
Run on Ubuntu platform: - Desktop / folder which contains all files:
- The Desktop folder contains the main.php file:
- Run on terminal:
- Output:
How to include () all PHP files from a directory? _files: Questions
How to include () all PHP files from a directory? PHP: Questions