alwaysbrasilian Posted April 30, 2009 Share Posted April 30, 2009 hey guys i've been working on this script for a while and can't get it to work the way i like. function decode($arg1, $arg2){ mysql_connect('localhost', 'root', 'woopwoop'); mysql_select_db('bluebiez_upload'); $result = mysql_query("SELECT data FROM $arg1 WHERE ID = '$arg2' "); $data = mysql_fetch_array($result); $encoded= $data['data']; $final = base64_decode($encoded); header("Content-type: image/gif"); return $final; } Now my problem is that if i put it in the first set of ' <?php .. ?> ' it works but it wont display the HTML content afterwords(just the image and nothing else). If i put it anywhere else after the php code up top it'll give me an error "The image “http://localhost/bluebiez/mypage.php” cannot be displayed, because it contains errors." Like i said it works in the begining of my code. I've tried two ways to print it out.. print decode('arg1', 'arg2'); <img src="data:image/gif; base64, <?php print decode('arg1', 'arg2'); ?>" /> .. so any ideas will be appreciated. Link to comment https://forums.phpfreaks.com/topic/156321-solved-question-about-content-type-image/ Share on other sites More sharing options...
sotusotusotu Posted April 30, 2009 Share Posted April 30, 2009 Presuming you are getting the correct data about the image from the DB. What about just trying: <img src="images/<?php print decode('arg1', 'arg2'); ?>" /> Link to comment https://forums.phpfreaks.com/topic/156321-solved-question-about-content-type-image/#findComment-823058 Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2009 Share Posted April 30, 2009 Every image on a page needs an <img tag - http://w3schools.com/html/html_images.asp The <img tag requires a URL of the image. When you are dynamically outputting images using php, the URL is of your .php script that outputs the header() followed by the image data. Link to comment https://forums.phpfreaks.com/topic/156321-solved-question-about-content-type-image/#findComment-823059 Share on other sites More sharing options...
alwaysbrasilian Posted April 30, 2009 Author Share Posted April 30, 2009 thx 4 the reply sotusotusotu but im not getting the image from a directory. I just tried your suggestion but no luck and pfmabismad i know that i should put it into an img tag but i have no idea.. Now if i want to input a argument through the browser like 'file.php?id=arg.' How can i pass multiple arguments through the browser(like file.php?table=arg1,id=arg2)? I know that i would have to use $_GET in my code. Link to comment https://forums.phpfreaks.com/topic/156321-solved-question-about-content-type-image/#findComment-823068 Share on other sites More sharing options...
alwaysbrasilian Posted April 30, 2009 Author Share Posted April 30, 2009 never mind i figured it out. i figured out a way to but it not the way i originally wanted(as a function) but as an independent file it works and i call it using <img src="decode-image.php?table=<?php echo arg1;?>&id=<?php echo arg2; ?>"/> if anyone else ever wants the full explanation hit me know Link to comment https://forums.phpfreaks.com/topic/156321-solved-question-about-content-type-image/#findComment-823103 Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2009 Share Posted April 30, 2009 Someone already told you that - When you are dynamically outputting images using php, the URL is of your .php script that outputs the header() followed by the image data. Link to comment https://forums.phpfreaks.com/topic/156321-solved-question-about-content-type-image/#findComment-823126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.