Easiest way to get list of files in the server directory

Tags: , , ,

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!


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}');

Source: stackoverflow