Wednesday, January 7, 2009

How to find a specific file type inside a folder using php - glob()

Using the glob() function you can search only for a given file type inside a folder.
glob() will return an array containg all file names with the given file type.
Following code will show you how to get a list of only .gif image files from the image folder.


<?php

//get only .gif files from images folder
$files_list = glob("images/*.gif");

foreach($files_list as $files)
{
echo $files;
echo '<br />';
}

?>

No comments:

Post a Comment