GrizzlyBear Posted July 27, 2008 Share Posted July 27, 2008 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 More sharing options...
genericnumber1 Posted July 27, 2008 Share Posted July 27, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600741 Share on other sites More sharing options...
PFMaBiSmAd Posted July 27, 2008 Share Posted July 27, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600742 Share on other sites More sharing options...
MFHJoe Posted July 27, 2008 Share Posted July 27, 2008 If you still want to do it like this, look at http://www.phpriot.com/articles/images-in-mysql/ Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600744 Share on other sites More sharing options...
LemonInflux Posted July 27, 2008 Share Posted July 27, 2008 Probably not helpful, but you may also find you can save space and speed up your queries a lot if you just save the files to a directory, then have a reference in the MySQL column Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600748 Share on other sites More sharing options...
GrizzlyBear Posted July 27, 2008 Author Share Posted July 27, 2008 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600758 Share on other sites More sharing options...
GrizzlyBear Posted July 27, 2008 Author Share Posted July 27, 2008 Can anyone help me with this script to see if it is right..it seems to be, but its not working. Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600770 Share on other sites More sharing options...
MasterACE14 Posted July 27, 2008 Share Posted July 27, 2008 not getting any errors? Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600772 Share on other sites More sharing options...
GrizzlyBear Posted July 27, 2008 Author Share Posted July 27, 2008 Nope..no errors hey, It shows the image place holder, but just not the image. Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600781 Share on other sites More sharing options...
PFMaBiSmAd Posted July 27, 2008 Share Posted July 27, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116827-display-an-image-help-please/#findComment-600822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.