rebeat Posted March 25, 2006 Share Posted March 25, 2006 Hi,I am trying to display images within my page dynamically using the ? call function, the way i want to link and include an image for example is: index.php?image=photo1.jpgthe code on my index.php page is as follows:<?phpif (!$image) {echo "<img src='$image'>";}else {echo "no image to display";}?>this is not working, just keps showing me the else function... i have played with it and googled for HOURS, even trying the print and include commands... include writes the jpg as ascii.. any help would be greatly appreciated :)cheers, wayne Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/ Share on other sites More sharing options...
annihilate Posted March 25, 2006 Share Posted March 25, 2006 It will never show for you because you are saying if the variable image is not set, show the image. Try this:[code]if (isset($_GET['image'])){$image = $_GET['image'];// Do some validation on the image string here, if passes then show image// Obviously need to provide full path to image unless it is in same folder as script// eg <img src="images/'.$image.'" />echo '<img src="'.$image.'" />'; }else{echo 'No image to display';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-20603 Share on other sites More sharing options...
freakus_maximus Posted March 26, 2006 Share Posted March 26, 2006 [!--quoteo(post=358275:date=Mar 25 2006, 12:19 PM:name=annihilate)--][div class=\'quotetop\']QUOTE(annihilate @ Mar 25 2006, 12:19 PM) [snapback]358275[/snapback][/div][div class=\'quotemain\'][!--quotec--]// Do some validation on the image string here, if passes then show image// Obviously need to provide full path to image unless it is in same folder as script[/quote]You can store the path and image name in the database tho and output it like "images/myimage.jpg"I recommend this method so you do not have to rely on keeping your images in the same folder or specifically noting it in the code. Helpful if you have images divided up into catagory named folders.I needed to do this for a photography website and it worked great. Especially when returning search results which need to display images also. Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-20763 Share on other sites More sharing options...
rebeat Posted March 27, 2006 Author Share Posted March 27, 2006 Thankyou annihilate for the code and freakus_maximus for the tip ;) works fantastic. on a side note to this post... i would like to be able to call a dynamic page, eg: index.php?id=page1.php within my index --but-- also to be able to call an image eg: index.php?image=images/test.jpg (this would also give me the option to insert dynamic images on dynamic pages, ie: index.php?id=page2.php&image=photo2.jpg) --but if i dont specify a page 'id' i would like just the image.Here is the code i have so far (obviously it doesnt work correctly as i have a default 'id' value of 'home.php' in order to fill the index.php home page by default.[code]<?phpif (!$id) {$id = "home.php";$include = $id;}else {$include = $id;}if (is_file($include) == "1") { include $include;}else {include "404.php";}if (isset($_GET['image'])){$image = $_GET['image'];// Do some validation on the image string here, if passes then show image// Obviously need to provide full path to image unless it is in same folder as script// eg <img src="images/'.$image.'" />echo '<img src="'.$image.'" />';}?>[/code]--------------what i am trying to achieve is IF there is JUST an index.php?image= call, then the default ?id=home.php is ignored? but still be able to call both, ie: index.php?id=page2.php&image=photo2.jpg if i need to -- i could create a blank.php page and call all images like: ?id=blank.php&image-photo1.jpg but there has to be a way to do this within the script. i could also just remove the 'home.php' value in the script, but then to view mysite.com would require mysite.com/?id=home to show default home page content.again, any help is greatly appreciated :)cheers, wayne. Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-21098 Share on other sites More sharing options...
annihilate Posted March 27, 2006 Share Posted March 27, 2006 Try this:[code]<?phpif ( isset($_GET['id']) && $_GET['id'] <> '' ){$include = $_GET['id'];}else // No page specified, so set a default{$include = 'home.php';}if ( is_file($include) ) {include $include;}else{include '404.php';}if ( isset($_GET['image']) && $_GET['image'] <> '' ){$image = $_GET['image'];// Do some validation on the image string here, if passes then show image// Obviously need to provide full path to image unless it is in same folder as script// eg <img src="images/'.$image.'" />echo '<img src="'.$image.'" />';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-21153 Share on other sites More sharing options...
rebeat Posted March 27, 2006 Author Share Posted March 27, 2006 Thx annihilate for the help. I have uploaded the script, if i choose JUST the ?image= command, it still seems to show the default home.php. Im not sure if what i want can be done... * if nothing is specified, the default home.php is displayed ONLY* if JUST ?image=photo.jpg --only the image is displayed (home.php is NOT displayed)* if ?id=anypage.php&image=photo.jpg --both are shown dynamicallyhere's a working example of the script above, calling JUST the image (see bottom of page):[a href=\"http://dunebuggies.com.au/home/newsite/test1.php?image=action_640.jpg\" target=\"_blank\"]http://dunebuggies.com.au/home/newsite/tes...=action_640.jpg[/a]the test1.php only has the php script above, nothing else, it is including the home.php by default. maybe it needs another else command or maybe elseif to check if the id does NOT exist BUT the image does, to display it, if false, then display the home.php or 404.I have played around with it will no success.If it is not possible to do, i will just create a blank page say, blank.php to overwrite the home.php defaultany ideas?thanks again, wayne Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-21172 Share on other sites More sharing options...
annihilate Posted March 27, 2006 Share Posted March 27, 2006 Try this:If you view the page passing no variables in the url, then home.php is included.If you specify an image to view, them image is shown, nothing is inlcuded.If you specify just an id, then that is included if it exists, else 404.php is included.If you specify a page and image, then both are shown. [code]<?phpif ( isset($_GET['id']) && $_GET['id'] <> '' ) // If id is set, then set include to that value{$include = $_GET['id'];}elseif ( (!isset($_GET['id']) || $_GET['id'] == '') && isset($_GET['image']) ) // If id not set, but image is, don't include anything{$include = FALSE;}else // id and image not set, so include a default page{$include = 'home.php';}if ( $include != FALSE){ if ( is_file($include) ) // If finds file, then include it { include $include; } else // File doesn't exist, so show 404 page { include '404.php'; }}// Show the image if setif ( isset($_GET['image']) && $_GET['image'] <> '' ){$image = $_GET['image'];// Do some validation on the image string here, if passes then show image// Obviously need to provide full path to image unless it is in same folder as script// eg <img src="images/'.$image.'" />echo '<img src="'.$image.'" />';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-21186 Share on other sites More sharing options...
rebeat Posted March 28, 2006 Author Share Posted March 28, 2006 Thankyou annihilate, it works great, just what i wanted, your a champion!! cheers and best regards, wayne. Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-21580 Share on other sites More sharing options...
annihilate Posted March 28, 2006 Share Posted March 28, 2006 No problem. Glad you have it working the way you want. Quote Link to comment https://forums.phpfreaks.com/topic/5782-dynamic-image-display-using-php-id-tag-pls-help/#findComment-21592 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.