How to Get List of File In Folder In php?
hi Guys,
In this example,I will learn you how to how to get list of file in folder in php. you can esay and simply get list of file in folder in php.
The scandir() function in PHP is an inbuilt function which is used to return an array of files and directories of the specified directory. The scandir() function lists the files and directories which are present inside a specified path.
Example 1 :
<?php
$mydir = 'dummy';
$myfiles = array_diff(scandir($mydir), array('.', '..'));
print_r($myfiles);
?>
Output :
Array (
[2] => demo
[3] => demo2
[4] => test1.php
[5] => test2.php
[6] => test3.txt
)
Example 2 :
<?php
$fileList = glob('test/*');
foreach($fileList as $filename){
if(is_file($filename)){
echo $filename, '<br>';
}
}
?>
Output :
dummy/test1.php
dummy/test2.php
dummy/test3.txt
Example 3 :
<?php
$fileList = glob('test/*.php');
foreach($fileList as $filename){
if(is_file($filename)){
echo $filename, '<br>';
}
}
?>
Output :
dummy/test1.php
dummy/test2.php
It will help you....
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example