Skip to content
PHP Logo

How can PHP be used to display all files in a specific directory path?

To display all files in a specific directory path using PHP, you can use the `scandir()` function to retrieve an array of all files and directories in the specified path. You can then loop through this array and display only the files using a simple conditional check.

php
$directory = "/path/to/directory";

$files = scandir($directory);

foreach($files as $file){
    if(is_file($directory . '/' . $file)){
        echo $file . "<br>";
    }
}