Page 1 of 1
Retrieving image data from mysql using php
Posted: Mon Aug 02, 2010 10:39 am
by pravin3009
I am trying to retrieve image (blob data ) from mysql, I able to do that successfully, the problem is it is not forming an image with the help of html image control. following the code that i am trying..
//following code from where I am retriving the image data is in getImage.php file -
<?php
mysql_connect("localhost:3308","user","password") or die("Unable to connect to SQL server");
@mysql_select_db("dbname") or die("Unable to select database");
$result=mysql_query("select * from tblName where rowid=1") or die("Can't perform Query");
$data=@MYSQL_RESULT($result,0,"content_image");
Header("Content-type: image/jpeg");
echo ("$data");
?>
and following is the code from the page I am calling this page.
<td>
<?php
echo "<img src=\"getImage.php\" height='200' width='400' />";
?>
</td>
this is first time I am programming php, and I am a two day old programmer, any help on this is highly appriciated. waiting for the responses.
Re: Retrieving image data from mysql using php
Posted: Mon Aug 02, 2010 10:44 am
by AbraCadaver
Do you get any errors? If you view source in the browser, is there any image data there?
Re: Retrieving image data from mysql using php
Posted: Mon Aug 02, 2010 10:51 am
by pravin3009
no errors, this is what the view source show -
<td>
<!-- Image1 -->
<img src="getImage.php" height='200' width='400' />
</td >
But instead of doing
<?php
echo "<img src=\"getImage.php\" height='200' width='400' />";
?>
however, If i do
<?php
include "getImage.php"
?>
It shows the binary data into the <td> element. that makes me sure that the data is coming from the database. Also with the echo statement it show the image contol with a cross mark at top left corner, if I right click on the image control and say view properties, it shows me the url of "
http://localhost/hello/getImage.php" and dimensions of the image as declared for the html img control.
Re: Retrieving image data from mysql using php
Posted: Mon Aug 02, 2010 10:56 am
by AbraCadaver
Does the binary data contain any \ characters? If so, then the data was probably escaped before it was inserted (maybe magic_quotes_gpc), or it is being escaped automatically coming out (maybe magic_quotes_runtime). Try this:
Re: Retrieving image data from mysql using php
Posted: Mon Aug 02, 2010 11:08 am
by pravin3009
no help with that. I did not inserted images into the database by adding escape characters, what i did was, I used mysql command prompt to insert the values into the table and for inserting the image I used LoadImage or LoadFrom ( i dont remember exactly).
just for information in case, I get the following lines at the bottom of my html page -
No log handling enabled - turning on stderr logging Cannot find module (IP-MIB): At line 0 in (none) Cannot find module (IF-MIB): At line 0 in (none) Cannot find module (TCP-MIB): At line 0 in (none) Cannot find module (UDP-MIB): At line 0 in (none) Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none) Cannot find module (SNMPv2-MIB): At line 0 in (none) Cannot find module (SNMPv2-SMI): At line 0 in (none) Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none) Cannot find module (UCD-SNMP-MIB): At line 0 in (none) Cannot find module (UCD-DEMO-MIB): At line 0 in (none) Cannot find module (SNMP-TARGET-MIB): At line 0 in (none) Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none) Cannot find module (DISMAN-EVENT-MIB): At line 0 in (none) Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none) Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none) Cannot find module (UCD-DLMOD-MIB): At line 0 in (none) Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none) Cannot find module (SNMP-MPD-MIB): At line 0 in (none) Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none) Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none) Cannot find module (SNMPv2-TM): At line 0 in (none)
is that causing the problem? I installed the php and mysql two days back, do I have to update the "ini" file for any settings?