flynryan692 Posted September 9, 2012 Share Posted September 9, 2012 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 https://forums.phpfreaks.com/topic/268170-checking-if-image-exists-then-displaying-it/ Share on other sites More sharing options...
trq Posted September 9, 2012 Share Posted September 9, 2012 Variables are not interpolated within single quotes. $pathtofile = ($_SERVER['DOCUMENT_ROOT'] . '/cms/images/airlines/$icao.jpg'); Should be: $pathtofile = $_SERVER['DOCUMENT_ROOT'] . "/cms/images/airlines/$icao.jpg"; Link to comment https://forums.phpfreaks.com/topic/268170-checking-if-image-exists-then-displaying-it/#findComment-1376388 Share on other sites More sharing options...
flynryan692 Posted September 9, 2012 Author Share Posted September 9, 2012 That did it, thank you! I didn't think it would be as simple as single quotes vs double quotes. Link to comment https://forums.phpfreaks.com/topic/268170-checking-if-image-exists-then-displaying-it/#findComment-1376390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.