Jump to content

[SOLVED] question about content-type image


alwaysbrasilian

Recommended Posts

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.

 

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.

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.