List all files in one directory PHP [duplicate] List all files in one directory PHP [duplicate] php php

List all files in one directory PHP [duplicate]


You are looking for the command scandir.

$path    = '/tmp';$files = scandir($path);

Following code will remove . and .. from the returned array from scandir:

$files = array_diff(scandir($path), array('.', '..'));


Check this out : readdir()

This bit of code should list all entries in a certain directory:

if ($handle = opendir('.')) {    while (false !== ($entry = readdir($handle))) {        if ($entry != "." && $entry != "..") {            echo "$entry\n";        }    }    closedir($handle);}

Edit: miah's solution is much more elegant than mine, you should use his solution instead.