Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Get list of all filenames contained within my images directory [duplicate]

Tags:

php

I have been trying to figure out a way to list all files contained within a directory. I'm not quite good enough with php to solve it on my own so hopefully someone here can help me out.

I need a simple php script that will load all filenames contained within my images directory into an array. Any help would be greatly appreciated, thanks!

like image 738
lewisqic Avatar asked Jan 13 '10 20:01

lewisqic


2 Answers

Try glob

Something like:

 foreach(glob('./images/*.*') as $filename){      echo $filename;  } 
like image 61
a.yastreb Avatar answered Sep 16 '22 23:09

a.yastreb


scandir() - List files and directories inside the specified path

$images = scandir("images", 1); print_r($images); 

Produces:

Array (     [0] => apples.jpg     [1] => oranges.png     [2] => grapes.gif     [3] => ..     [4] => . ) 
like image 37
Sampson Avatar answered Sep 19 '22 23:09

Sampson