I wrote this to read the current dir and retun all the file names if they are image files.Right now it just takes the returned file names and prints them to a page with the img tag so you can see the images. What I am wondering is if there is a cleaner way to do so. Im not too PHP savy but I was wondering what the PHP experts think.Thanks!
//Create list of Images$list = array();if ($dir = opendir('./')){ while ($file = readdir($dir)) { //Finds image files if (eregi('^(.+\.(((j|J)(p|P)(g|G))|((g|G)(i|I)(f|F))|((p|P)(n|N)(g|G))))$', $file)) $list[] = $file; } closedir($dir);}asort($list); // sort alphaforeach ($list as $pic){ echo "img src='$pic' br"; $i++;}?>
1/8/2006 4:48:55 PM
if (eregi('^(.+\.((jpg))|(gif)|(png)))$', $file))
1/8/2006 5:27:19 PM
Hey thanks!will do
1/8/2006 8:11:15 PM
preg_match("/\.(gif|jpg|png)$/i", $file);Should be faster.[Edited on January 8, 2006 at 9:40 PM. Reason : .]
1/8/2006 9:37:41 PM
yea preg functions are MUCH faster.
1/8/2006 10:01:50 PM
yep thats what I ended up doing.I was just waiting for the Noen comment.
1/8/2006 11:01:02 PM
1/9/2006 12:20:13 AM
when you're in the know, you're Noen
1/9/2006 1:11:10 AM
ohh thats bad!
1/9/2006 1:45:53 AM