czukoman20 Posted March 11, 2008 Share Posted March 11, 2008 I have a piece of coding right now that calls for a users certain banner image. The problem is. Many users want to use different banners. So i have the code in my pagination page which searches for different banners and then displays them by the search. Well the only issue is that it only supports one file type... .jpeg. echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.jpg\" width=\"600\" height=\"110\"><br />"; that is the banner code. How would i be able to make that say.. heyy if that banner is not there maybe i should check a different file format. ??? I would really appreciate some help please Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/ Share on other sites More sharing options...
bob_the _builder Posted March 11, 2008 Share Posted March 11, 2008 Hi, I guess you are allready quering the database .. So maybe something like if ($imagefield == '') { echo 'No Banner'; }else{ echo 'Link to banner here'; } hth Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489069 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 Thats hardly php scripting.. echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.jpg\" width=\"600\" height=\"110\"><br />"; some effort would be nice try something like <?php $types = array("jpg","gif","png"); $dir = "path/to/image/"; foreach($types as $type) { if(file_exists($dir.$username ."_banner.".$type)) { echo "<a href=\"http://www.adworld-online.com/submit.php?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type.\" width=\"600\" height=\"110\"><br />"; } } ?> Ok thats written on the fly.. just a basic idea Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489070 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 ok i will give that one a try feed back will be soon Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489073 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 <?phpif($session->logged_in){ $sub = "submit.php"; } else{ $sub = "submit2.php"; } $types = array("jpg","gif","png","swf"); $dir = "http://www.adworld/online.com/images/banners/"; foreach($types as $type) { if(file_exists($dir.$username ."_banner.".$type)) { echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><imgsrc=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type." width=\"600\" height=\"110\"><br />"; } } ?> Im getting a parse error on the last line of the code which is embedded in a template and this is all i changed soo i'm not sure where the issue is. Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489082 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 try this <?php if($session->logged_in) { $sub = "submit.php"; }else{ $sub = "submit2.php"; } $types = array("jpg","gif","png","swf"); $dir = "http://www.adworld/online.com/images/banners/"; foreach($types as $type) { if(file_exists($dir.$username ."_banner.".$type)) { echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type."\" width=\"600\" height=\"110\"><br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489087 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 Ok well the code is working now.. but i have a .jpg banner in there and its not showing up.. hmm. i will take a closer look and get back to ya. Any Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489108 Share on other sites More sharing options...
wmguk Posted March 11, 2008 Share Posted March 11, 2008 just spotted $dir = "http://www.adworld/online.com/images/banners/"; you may have already spotted it and changed it, but might explain why banners arent being displayed? try $dir = "http://www.adworld-online.com/images/banners/"; Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489113 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 well yes i spotted that. but thanks. I changed it and... still nothing. The error is happening at the if(file_exists($dir.$username ."_banner.".$type)) thats not seeing the file for some wierd reason. the directory of the file is. http://www.adworld-online.com/images/banners/mmallon_banner.jpg and well for some reason, its not showing that it even exists. Hmm any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489125 Share on other sites More sharing options...
wmguk Posted March 11, 2008 Share Posted March 11, 2008 try removing the space after $username? i dont really know much about php so its just stabs in the dark... but maybe lol Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489129 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 nope .. do u want me to post the whole entire code that im workin with Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489132 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 change $dir = "http://www.adworld-online.com/images/banners/"; to $dir = dirname(__FILE__)."images/banners/"; assuming the script is on the top level Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-489325 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 ok well i think i may have found an issue with all of this in the first play. THE $types function is just displayed as Array I have added an else echo <?php if($session->logged_in) { $sub = "submit.php"; }else{ $sub = "submit2.php"; } $types = array("jpg","gif","png","swf"); $dir = "http://www.adworld-online.com/images/banners/"; foreach($types as $type) { if(file_exists($dir.$username ."_banner.".$type)) { echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/". $username ."_banner.".$type."\" width=\"600\" height=\"110\"><br />"; }else{ echo "$types"; echo "<br>"; echo "$dir"; echo "<br>"; echo "$username"; echo "<br>"; echo "$type"; } } } ?> else{ echo "$types"; echo "<br>"; echo "$dir"; echo "<br>"; echo "$username"; echo "<br>"; echo "$type"; } thats the else statement.. here is what i says types returns as a value of "array" dir returns the right directory. and type returns as "jpgarray". i think this might be the issue.. but how do i resolve this.. Please help me out guys. any trys will be helpful username returns the right username.. .so the issue is the actual $types code. Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490018 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 $types is an array $type is the filetype as i said the problem is here $dir = "http://www.adworld-online.com/images/banners/"; your using a HTML path not a FILE path use $dir = dirname(__FILE__)."/images/banners/"; Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490036 Share on other sites More sharing options...
czukoman20 Posted March 11, 2008 Author Share Posted March 11, 2008 <?phpif($session->logged_in) { $sub = "submit.php"; }else{ $sub = "submit2.php"; } $types = array("jpg","gif","png","swf"); $dir = dirname(__FILE__)."images/banners/"; foreach($types as $type) { if(file_exists($dir.$username."_banner.".$type)) { echo "<a href=\"http://www.adworld-online.com/$sub?user=$username\"><img src=\"http://www.adworld-online.com/images/banners/".$username."_banner.".$type."\" width=\"600\" height=\"110\"><br />"; } } ?> well i forgot to say that i also tried this.. It still doesn't show up. the if file_exists isn't being triggered. soo idk what else... Thank you for your help so far. More help is appreciated please. this file is located at www.adworld-online.com/browse/sto.php the picture is located in two places www.adworld-online.com/browse/images/banners/mmallon_banner.jpg www.adworld-online.com/images/banners/mmallon_banner.jpg Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490055 Share on other sites More sharing options...
MadTechie Posted March 11, 2008 Share Posted March 11, 2008 check your code $dir = dirname(__FILE__)."/images/banners/"; $dir = dirname(__FILE__)."images/banners/"; also it depends on here the file (its running from) is located.. compared to the images folder Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490058 Share on other sites More sharing options...
czukoman20 Posted March 12, 2008 Author Share Posted March 12, 2008 where does the file have to be located compared to the image? could you give me an example directory Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490064 Share on other sites More sharing options...
czukoman20 Posted March 12, 2008 Author Share Posted March 12, 2008 Ok thank you soooo much man .. you rock. It works .. Ok just one last question... where is the SOLVED BUTTON>.... is it gone? Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490070 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 okay / = root /images/banners/madtechie_banner.jpg /image.php your use this $dir = dirname(__FILE__)."/images/banners/"; / = root /images/banners/madtechie_banner.jpg /class/image.php your use this $dir = dirname(__FILE__)."/../images/banners/"; try printing the $dir and check its pointing to the correct place ahh i just typed this... Ok the solved button has been removed but i'll take your last post as a solved Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490075 Share on other sites More sharing options...
czukoman20 Posted March 12, 2008 Author Share Posted March 12, 2008 any particular reason why it was removed? problems? Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490078 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 Its a mod to the standard SMF (this fourm) i believe the forum had an upgrade or something and the admins haven't added it back in (but i am not 100% sure) Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490083 Share on other sites More sharing options...
czukoman20 Posted March 12, 2008 Author Share Posted March 12, 2008 ok so its more of a lazy reason i guess. no offense to them or anything Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490086 Share on other sites More sharing options...
MadTechie Posted March 12, 2008 Share Posted March 12, 2008 maybe they are short of php programmers!! who know.. Just Kidding Guys & Girls adding a mod can be a pain plus the site is offline for a little while and i maybe wrong! Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490089 Share on other sites More sharing options...
czukoman20 Posted March 12, 2008 Author Share Posted March 12, 2008 lol i guess so. O well. that feature was a pretty good idea. ok well thanks for helpin me out man. Quote Link to comment https://forums.phpfreaks.com/topic/95538-if-image-isnt-present/#findComment-490102 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.