suess0r Posted January 6, 2007 Share Posted January 6, 2007 Hey i'm trying to do a call to check if an image exists, if so set the image to $id.jpg else set the image to default.jpg[quote]echo '<b><p align="center"><img src="/images/clubs/logos/'.$id.'.jpg" align="center" width="300" height="128"></p>';[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/ Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 Look up http://us3.php.net/file_existsThe manual is really good if you just type in what you want it finds close functions.[code]if(file_exists($yourFile)){ $id = 'default';}else{ $id = $yourFile;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154393 Share on other sites More sharing options...
ToonMariner Posted January 6, 2007 Share Posted January 6, 2007 [code]<?phpif (is_file(FULL_PATH_TO_YOUR_IMAGE)){ $path = FULL_PATH_TO_YOUR_IMAGE;}else{ $path = '/common/images/default.jpg';}$size = getimagesize($path);?> <p align="center"> <img src="<?php echo $path; ?>" <?php echo $size[3]; ?> /> </p>[/code]Thats a nice way of doing it - even adjusts for the height and width of the images incase they change! Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154402 Share on other sites More sharing options...
suess0r Posted January 6, 2007 Author Share Posted January 6, 2007 here's how i have it set up and i'm about to try those other waysbut it's not working... $defaultImage = "/images/clubs/logo/default.jpg"; $myImage = "/images/clubs/logos/".$id.".jpg"; if (file_exists($myImage)) { $img = $myImage; } else { $img = $defaultImage; } echo '<b><p align="center"><img src="'.$img.'" align="center" width="300" height="128"></p>'; Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154403 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 What isn't working.Just saying it isn't working doesn't give us much to go on. Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154412 Share on other sites More sharing options...
suess0r Posted January 6, 2007 Author Share Posted January 6, 2007 I'm sorry, it's just giving me a [x] where the picture should be. and i made sure the picture exists and it does... Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154420 Share on other sites More sharing options...
ToonMariner Posted January 6, 2007 Share Posted January 6, 2007 can you copy and past the html your script generates please..tryif (file_exists($_SERVER['DOCUMENT_ROOT . $myImage))see if that helps - sometimes i have a bit of bother with tgetting the path correct - purely because I am a lazy ass and can't be bothered to pay attention until someone else points out what I have doen wrong. Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154422 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 View the source of the outputted page. You probably have an HTML error now. Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154424 Share on other sites More sharing options...
suess0r Posted January 6, 2007 Author Share Posted January 6, 2007 Toon there's something wrong with that syntax with the ']' and you were right jesi i did have an html error on my dir i was calling the default...problem now the default image shows up no matter what, even if the image does exist ;x Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154442 Share on other sites More sharing options...
suess0r Posted January 6, 2007 Author Share Posted January 6, 2007 OK so i've found out the root of the problem why it keeps posting the Default image no matter what....[quote] $defaultImage = "/images/clubs/logos/default.jpg"; $myImage = "/images/clubs/logos/".$id.".jpg"; if (file_exists($myImage)) { $img = $myImage; } else { $img = $defaultImage; } echo '<p align="center"><img src="'.$img.'" align="center" width="300" height="128"></p>';[/quote]i did an echo on $myImage and it was the correct name of the image, and after the if statement i did an echo $img and it's default.jpg no matter what... so the if statement isn't working correctly with the file_exists() function... i tried the file_exists($_SERVER['DOCUMENT_ROOT.$myImage)) but the syntax isn't right... IS there a better way to see if the file exists?!? Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154474 Share on other sites More sharing options...
ToonMariner Posted January 6, 2007 Share Posted January 6, 2007 suppose is_file is slighlty more desirable in this case but they do similar things.remember that while html understands that '/images/this.jpg' is the same as 'http://www.asite.com/images/this.jpg' php doesn't. the string you put in there MUST let the scrip locate it from where teh scriupt is on teh server - which is why I tend to use $_server['document_root'] Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154519 Share on other sites More sharing options...
Jessica Posted January 6, 2007 Share Posted January 6, 2007 /images is not your root folder. If images is a sub folder of the folder this php file is in you can do ./imagesOtherwise you need your whole path which would be like $_server['document_root'].'/images..etc (or $_server['document_root'].'images...etc) Quote Link to comment https://forums.phpfreaks.com/topic/33137-default-image-help/#findComment-154525 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.