Displaying images in a directory with certain filenames

Hi! I’m a total PHP noob and i’m looking for a script that will scan an image directory, and display all images on a page with a specified filename. I don’t know if this is possible… Say i have a directory containing

filename01.png
filename02.png
filename03.png
filename04.png
filename05.png
image02.png
image04.png

is there any way i can make only the images starting with filename appear on a page?

If so, how do i do it?

thanks so much in advance for any help!

Try this:

[php]$dir = ‘images/’;
$files = preg_grep(’/^filename.+.png$/’,scandir($dir));
foreach($files as $img)
{
echo ‘
’;
}[/php]

Not tested, but should work (with pngs only). If it doesn’t work or you want it to use a different file extension (or any file extension) let me know.

Thanks so much! Is there any way i could make different filenames show up? Like a list of them.

Sponsor our Newsletter | Privacy Policy | Terms of Service