Jump to content

Getting random characters instead of IMAGE in PHP


anirudhtomer

Recommended Posts

hi everyone,

 

my php code is as follows

 

<?php

 

$connection = mysql_connect("localhost","xxxx","xxxx");

mysql_connect_db("xxxxx",$connection);

 

 

header("Content-type: text/html");

header("Content-type: image/jpg");

 

echo "<b> THE MOTOR DRIVING LICENSE <b>";

echo "<img src = 'pic.jpg' />";  //pic.jpg is an image at server

 

$result = mysql_query("select image from license); 

$rowdata = mysql_fetch_array($result);

 

/*** license is the name of table and image is the column with MEDIUM BLOB DATA TYPE ***/

 

$image =  $rowdata['image'];

 

echo $image;  //browser displays random charactes instead of image

 

?>

 

NOW THE OUTPUT I GET IS SOME RANDOM CHARACTERS INSTEAD OF THE IMAGE I AM EXPECTING FROM THE DATABASE.

 

when I try to print the image just below the header defining the content type as image , then I get the name of my php file printed in my browser & nothing else

 

Please enlighten me, where I am making a mistake & correct me.

 

THANKS IN ADVANCE

I assume you mean something like this

 

echo "<b> THE MOTOR DRIVING LICENSE <b>";
echo "<img src = 'image.php' />";  //pic.jpg is an image at server

 

<?php

$connection = mysql_connect("localhost","xxxx","xxxx");
mysql_connect_db("xxxxx",$connection);
header("Content-type: image/jpg");
$result = mysql_query("select image from license"); 
$rowdata = mysql_fetch_array($result);
echo $rowdata['image'];  //browser displays random charactes instead of image

?>

 

Of course your probably want to pass a value via get (the url) to the image script to allow the database to pick up the correct image

well I am sending the primary key of the table via post method to select the appropriate image.

that code I have not added here ... I have sent a simplified code here...

 

so isn't it possible to print HTML text & image from database together...

the problem is not how i get the image from database ... without the html part it prints the image perfectly..problem arises when use HTML text in PHP file...

 

& even If I remove the line

 

echo "<img src = 'pic.jpg' />";

 

& only keep the line

 

echo "<b> xxxx </b>";

 

it is not showing any image

yipppeeee some success...

 

Mad Techie as u had hinted me..I now try to print my image using another php file...& it prints successfully but now I don't know how to send the primary key of my table to that php file to select the right image ... do I have to embed it in my URL... any help

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.