fubarur Posted March 6, 2007 Share Posted March 6, 2007 I need help on a bit of code to look in a folder and see if there is a image with a certain name, if there is not one display this image instead. The details looking into this folder /images/event/XX/images/ XX is $id so it is a variable depending on the event you are looking at. The image name header_1.jpg else if it can not find the above load this default image /images/event_header.jpg Any help or pointers would be appreciated. I'm sure this is a noob type question, but I'm learning and this is one great resource! Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/ Share on other sites More sharing options...
willpower Posted March 6, 2007 Share Posted March 6, 2007 if (file_exists("http://whatever")) { //do this } else { //do that } Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201280 Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 you need file_exists() and you may get some use out of mime_content_type() @willpower: i believe you should only use the path for file_exists. not the url. Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201282 Share on other sites More sharing options...
willpower Posted March 6, 2007 Share Posted March 6, 2007 that may be the case, however i have used this on external domains and it has worked. Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201285 Share on other sites More sharing options...
fubarur Posted March 6, 2007 Author Share Posted March 6, 2007 if (file_exists("http://whatever")) { //do this } else { //do that } I tried this and it did not work? <?php if (file_exists("<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg")) { <img border="0" src="<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg>" /> } else { <img border="0" src="<?=Environment::webroot()?>/images/header_1.jpg>" /> } ?> Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201288 Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 @fubarur: you've got the syntax wrong. try: if (file_exists("/images/event/$id/images/header_1.jpg")) @willpower: good to know =) Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201293 Share on other sites More sharing options...
willpower Posted March 6, 2007 Share Posted March 6, 2007 hmmm not sure about the code thing going on there...BUT you have not escaped your php if (file_exists("<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg")) {?> <img border="0" src="<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg>" /> <?} else {?> <img border="0" src="<?=Environment::webroot()?>/images/header_1.jpg>" /> <?} ?> Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201294 Share on other sites More sharing options...
fubarur Posted March 6, 2007 Author Share Posted March 6, 2007 @fubarur: you've got the syntax wrong. try: if (file_exists("/images/event/$id/images/header_1.jpg")) @willpower: good to know =) This gave me a blank page like the last one did <?php if (file_exists("/images/event/$id/images/header_1.jpg")) { <img border="0" src="<?=Environment::webroot()?>/images/event/$id/images/header_1.jpg>" /> } else { <img border="0" src="<?=Environment::webroot()?>/images/header_1.jpg>" /> } ?> With the above code removed page loads fine Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201296 Share on other sites More sharing options...
willpower Posted March 6, 2007 Share Posted March 6, 2007 have you escaped your php as per my post. no evidence of it on yoru update Will Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201299 Share on other sites More sharing options...
fubarur Posted March 7, 2007 Author Share Posted March 7, 2007 have you escaped your php as per my post. no evidence of it on yoru update Will What do you mean "Escaped your PHP"? Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201300 Share on other sites More sharing options...
willpower Posted March 7, 2007 Share Posted March 7, 2007 read my post! i gave you code and you dont seem to have used it. You have PHP and HTML mixed together. Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201367 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 <?php if (file_exists("/images/event/$id/images/header_1.jpg")) { echo"<img border='0' src='<?php Environment: :webroot()?>/images/event/$id/images/header_1.jpg'></img>>"; }else{ echo"<img border='0' src='<?php Environment: :webroot()?>/images/header_1.jpg'></img>"; } ?> Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201370 Share on other sites More sharing options...
fubarur Posted March 7, 2007 Author Share Posted March 7, 2007 read my post! i gave you code and you dont seem to have used it. You have PHP and HTML mixed together. Ok, I think this is what you are talking about, but I used this code below and get a blank page? <?php if (file_exists("/images/events/$id/images/header_1.jpg")) ?> <img border="0" src="<?=Environment::webroot()?>/images/events/$id/images/header_1.jpg"> <?php else; ?> <img border="0" src="<?=Environment::webroot()?>/images/header.jpg"> <?php if (file_exists("/images/event/$id/images/header_1.jpg")) { echo"<img border='0' src='<?php Environment: :webroot()?>/images/event/$id/images/header_1.jpg'></img>>"; }else{ echo"<img border='0' src='<?php Environment: :webroot()?>/images/header_1.jpg'></img>"; } ?> Your code <?php if (file_exists("/images/events/$id/images/header_1.jpg")) { echo"<img border='0' src='/images/events/$id/images/header_1.jpg'></img>>"; }else{ echo"<img border='0' src='images/header.jpg'></img>"; } ?> Gives me a page but its not finding the image, and its there? Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201450 Share on other sites More sharing options...
fubarur Posted March 7, 2007 Author Share Posted March 7, 2007 Good news! After looking at all your help I messed around with the code and got it to work! if (file_exists("/var/www/html/images/events/$id/images/header_1.jpg")) { echo"<img border='0' src='/images/events/$id/images/header_1.jpg'></img>"; }else{ echo"<img border='0' src='images/header.jpg'></img>"; } ?> Thanks for all your help and guidance! Link to comment https://forums.phpfreaks.com/topic/41538-solved-help-to-find-an-image-and-if-there-is-not-one-show-this-one/#findComment-201464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.