Theekopje Theekopje - 1 year ago 38
PHP Question

Get image JPG and jpg

I've been bothered by this problem for a while now.
I'm trying to load images in PHP but there are jpg and JPG images and when I try to load images by jpg the JPG ones are not found (obviously)

$img1 = '<img src="imgs/'.$firstImage.'.jpg"></img>';
$img2 = '<img src="imgs/'.$secondImage.'.jpg"></img>';
$img3 = '<img src="imgs/'.$thirdImage.'.jpg"></img>';
$img4 = '<img src="imgs/'.$fourthImae.'.jpg"></img>';

Any idea how to fix this problem?

I tried using
but that didn't work out well

if (file_exists(''.$firstImage.'.jpg')) {
$img1 = '<img src="imgs/'.$firstImage.'.jpg"></img>';
} else {
$img1 = '<img src="imgs/'.$firstImage.'.JPG"></img>';

Problem now is that it can't find the images with regular jpg. For example I try to load
but the script tries to load
because the file
doesn't exist, while it does exist and is placed in the folder while
isn't. It works with the JPG files. For example
is found because
doesn't exist so it loads the
one. But with the
ones it won't work. Any solutions?

With kind regards,

Answer Source

Just check for the file in your local directory, don't use the url

if(file_exists('imgs/'.$firstImage.'.jpg')) {

Most url wrapper don't support stat(), see (blue note about php5 at the end) and