Verifying if an image exists - case insensitive
Posted on 2006-03-20
I have a page on my PHP site in which I have to check whether a thumbnail image exists for a particular listing.
Right now it checks if "myimage123.jpg" exists, but I need to extend that search to myimage123.JPG as some digital cameras seem to uppercase the image extension, and those images will be uploaded by the site users. I'd also like to extend the image check to the same name but with alt. extensions, in particular PNG :
I'm not sure how to code in PHP that it should look for myimage123.jpg OR myimage123.JPG OR myimage123.png OR myimage123.PNG, based on the following :
// Pix definition
$housepicBIG1JPG = MY_UPLOAD_DIR.$reference."_1.jpg";
$housepicJPG = MY_UPLOAD_DIR.$reference."_1_mini.jpg";
//Thumb exists ?
$thumbpiccode="<img src=\"".$housepicJPG."\" alt=\"".$titre."\" class=\"estateselect\" />";
// else I create the thumbnail or send a warning etc...