php list all files in directory 1

php list all files in directory

$path    = './';
$files = scandir($path);
$files = array_diff(scandir($path), array('.', '..'));
foreach($files as $file){
  echo "$file";
}

Here is what the above code is Doing:
1. We’re using the scandir() function to get a list of all the files in the current directory.
2. We’re using the array_diff() function to remove the . and .. entries from the list.
3. We’re looping through the list of files and creating a link for each one.

Similar Posts