Jump to content

Checking if image exists, then displaying it


flynryan692

Recommended Posts

Here is what I am trying to do, I want to take the first three letters of a flight number known as the ICAO code from my database and then check if the logo of the airline exists in my folder full of images. If the image exists I want to display it next to my other information, if it does not I want to simply write "Unknown".

 

Here is what I have

 

$callsign = $row["Callsign"];
$icao = substr($callsign, 0, 3);
$pathtofile = ($_SERVER['DOCUMENT_ROOT'] . '/cms/images/airlines/$icao.jpg');
$exists = file_exists($pathtofile);

 

Then I have the following to display the image

 

<?php if ($exists) { ?>
<tr><td><?php echo $txt["airline"] ?>:</td><td></td><td><img src="http://www.mysiteurl.org/cms/images/airlines/<?php echo $icao ?>.jpg" /></td></tr>
<?php } else { ?>
<tr><td><?php echo $txt["airline"] ?>:</td><td></td><td>Unknown</td></tr>
<?php } ?>

 

For some reason it keeps showing up as "Unknown" meaning the image doesn't exist, when I know it does. If I simply use

echo $pathtofile

the image shows up, but when I use

$exists

or even

if file_exists($pathtofile)

it keeps telling me the file does not exist. Here is the the odd part, if I replace $icao in $pathofile with the an airline code then it works, which leads me to believe something could be wrong with $pathofile

 

Any ideas?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.