willdk Posted February 13, 2009 Share Posted February 13, 2009 Ok...I have a folder with images that I use in a page. BUT sometimes there is a broken link, because the image doesn't exist. SO I made t-blank.gif for the broken links. My code is not working...and I don't understand why ??? <img src="http://localhost/test/thumbs/t-<?php if (empty($url)) { echo 'blank'; } else { echo $url; } ?>.gif" border="0"> I get the last 'echo url' as result, and the 'echo blank' is not used when there is an error (it doesn't exist). Quote Link to comment Share on other sites More sharing options...
Philip Posted February 13, 2009 Share Posted February 13, 2009 <img src="http://localhost/test/thumbs/t-<?php if(!isset($url) || empty($url)) echo 'blank'; else echo $url; ?>.gif" border="0"> What does the source show? Quote Link to comment Share on other sites More sharing options...
willdk Posted February 13, 2009 Author Share Posted February 13, 2009 @KingPhilip No luck with your code. I still get empty spots for non-existing images. Because I know the path of the non-existing image, it must be someting with checking that path and then let the script show blank.gif or not. I tried something in this direction but no luck yet... $checurl = "http://localhost/test/thumbs/t-".$url.".gif" ... if (empty($checurl)) { echo 'blank'; } else { ... Quote Link to comment Share on other sites More sharing options...
Philip Posted February 13, 2009 Share Posted February 13, 2009 <img src="http://localhost/test/thumbs/t-<?php if(!isset($url) || empty($url)) echo 'blank'; else echo $url; ?>.gif" border="0"> What does the source show? Look at your browser's source code when you view the page. What do you see? You should see: <img src="http://localhost/test/thumbs/t-blank.gif" border="0"> That's what I see when I run the code. I'm thinking maybe your wanting to check to see if the file exists, and not if the variable is empty? Quote Link to comment Share on other sites More sharing options...
willdk Posted February 13, 2009 Author Share Posted February 13, 2009 When I use your code I get <img src="http://localhost/test/thumbs/t-image23.gif" border="0"> BUT t-image23.gif doesn't exist. And I think the solution is something with first checking if that image exists and then act. I think I made a mistake by thinking it was something with the var Quote Link to comment Share on other sites More sharing options...
sdi126 Posted February 13, 2009 Share Posted February 13, 2009 Yea you need to use the file_exists function. http://us2.php.net/manual/en/function.file-exists.php Quote Link to comment Share on other sites More sharing options...
willdk Posted February 13, 2009 Author Share Posted February 13, 2009 It's working I used file_exists...and because I'm using localhost I could not use $checurl = "http://localhost/test/thumbs/t-".$url.".gif" so the right path is $checurl = "file:///C:/..." KingPhilip and sdi126, Thank you both for your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.