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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.