Jump to content

Display an Image Help Please


GrizzlyBear

Recommended Posts

Hey

 

I need help being able to display an image which I have saved as a blob into my database. I have posted the script below where I have tried using the same method as text, but it displays incorrect and if anyone can help me out, it would be great.

 

Thanks,

Grizzly

 

<?php

include('connect.php');

$data = mysql_query("SELECT * FROM tblusers")
or die(mysql_error());
Print "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";

       
while($info = mysql_fetch_assoc( $data ))
{

Print   "<tr>
			<td width=\"20%\"><div align=\"right\">Firstname:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['firstname'] . "</div></td>
            	<td width=\"20%\"><div align=\"right\">Company:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['organization'] . "</div></td>
			<td align=\"center\" rowspan=\"6\" width=\"120\">".$info['title'] . "<img src=".$info['imgdata'] . " width=144></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Lastname:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['lastname'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Address:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['address1'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Tel Number:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['phone'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">City:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['city'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Cel Number:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['cell'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Province:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['province'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Fax Number:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['fax'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Country:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['country'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Email:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['email'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Age:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['age'] . "</div></td>								
		</tr>
		<tr>
		<td colspan=\"5\"></br></br><hr width=\"70%\"></br></br></td>
		</tr>";



}
Print "</table>";


				    ?>

Link to comment
https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/
Share on other sites

To display it, it must be in its own file with the correct header sent. You link to this external file as a regular <img> html tag...

 

for instance if it's a jpeg image....

 

<?php
header('Content-Type: image/jpeg');
echo $imageData;
?>

 

along with enough code to get the image data into the $imageData var of course.

Start by reading what HTML tag is necessary to place an image on a web page - http://www.w3schools.com/html/html_images.asp

 

The URL that is put into the src="..." parameter would be to your .php scrip that outputs the proper Content-type: header for the image followed by the binary data of the image.

Thanks for the reply. I have tried out the script below and it still doesn't display the image, i'm not sure what i'm doing wrong.

 

And Lemon, I orginally wanted to do that, but I'm new at learning php, and kinda had to settle for what works hey. I post a question on this forum already regarding that, but I have got useful replys. If you can suggest where I can maybe find an example, I will def give it a try.

 

Thanks.

 

 

This is the callingInfo2.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("statinfo");
$image = stripslashes($_REQUEST[title]);
$rs = mysql_query("SELECT * FROM tblusers where filename=\"".addslashes($image).".jpg\"");
$row = mysql_fetch_assoc($rs);
$imagedata = $row[imgdata];
header("Content-type: image/jpeg");
print $imagedata;
?>

 

 

<?php

include('connect.php');

$data = mysql_query("SELECT * FROM tblusers")
or die(mysql_error());
Print "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";

       
while($info = mysql_fetch_assoc( $data ))
{

Print   "<tr>
			<td width=\"20%\"><div align=\"right\">Firstname:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['firstname'] . "</div></td>
            	<td width=\"20%\"><div align=\"right\">Company:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['organization'] . "</div></td>
			<td align=\"center\" rowspan=\"6\" width=\"120\">".$info['title'] . "<img src=\"callingInfo2.php\" width=144></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Lastname:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['lastname'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Address:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['address1'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Tel Number:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['phone'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">City:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['city'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Cel Number:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['cell'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Province:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['province'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Fax Number:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['fax'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Country:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['country'] . "</div></td>
		</tr>
		<tr>
			<td width=\"20%\"><div align=\"right\">Email:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['email'] . "</div></td>
			<td width=\"20%\"><div align=\"right\">Age:</div></td>
			<td width=\"20%\"><div align=\"left\">".$info['age'] . "</div></td>								
		</tr>
		<tr>
		<td colspan=\"5\"></br></br><hr width=\"70%\"></br></br></td>
		</tr>";



}
Print "</table>";


				    ?>

Your main code is not putting any ?title= parameter on the end of the URL, so the image code is not receiving any $_GET['title'] variable. Please don't use $_REQUEST to avoid problems. If you are expecting an external variable on the end of the URL, use $_GET.

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.