Skipjackrick Posted February 29, 2008 Share Posted February 29, 2008 I am having problems with the following script. It only allows me to display images that are ".jpg" format. Sometimes the image might have the extension ".JPG" or ".gif" or ".GIF" or ."png" or ".PNG" How can I change the following script to accept the other file extensions? I tried altering this tiny snippet but I kept getting parse errors. if (preg_match('/\.jpg$/', $file)) { HELP ME PLEASE!!! Thanks. <?php if ($handle = opendir('/home/extremecoast/public_html/Kayak_Wars/Team_Original/uploaded_files/')) { while (false !== ($file = readdir($handle))) { if (preg_match('/\.jpg$/', $file)) { echo "<a href='$file' onclick='return hs.expand(this)' class='highslide'>\n"; echo "<img src='show_image.php?filename=$file&width=100&height=100' alt=''/>\n"; echo "</a>\n"; } } closedir($handle); } ?> Link to comment https://forums.phpfreaks.com/topic/93721-display-all-image-types/ Share on other sites More sharing options...
blackwinter Posted February 29, 2008 Share Posted February 29, 2008 if (preg_match("/(\.jpg|\.png|\.gif|\.jpeg)$/s", $file)) { Link to comment https://forums.phpfreaks.com/topic/93721-display-all-image-types/#findComment-480238 Share on other sites More sharing options...
tinker Posted February 29, 2008 Share Posted February 29, 2008 Just because i'm watching the weakest link: if (preg_match("/\.(jpg|png|gif|jpeg)$/i", $file)) { not sure if i'm right but i've changed the 's' to an 'i', ... Link to comment https://forums.phpfreaks.com/topic/93721-display-all-image-types/#findComment-480244 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.