Skip to content
Advertisement

Easiest way to get list of files in the server directory

I need to get array of all images (or simply of all files) in directory (e.g. www.example.com/images/). I prefer to use JavaScript but it’s hard to make. So should I use PHP, meybe?

Could you please help me – I’m not good at this.

Thank you very much!

Advertisement

Answer

Javascript cannot fetch all files on a server, as it is a client-side langugage.

http://php.net/manual/en/function.glob.php is what you need.

$all = glob('/path/to/dir/*.*');

$images = glob('/path/to/dir/*.{jpg,png,gif}');
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement