By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 941 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to display .png file from MySql in php?

P: 43
my .png files r stored as a blob in MySql,
I wanna to display them out in php through a web browser.

this is part of code (in php):

---after connect to database ,
Expand|Select|Wrap|Line Numbers
  1. $dbQuery=" select name, png1, png2  from png";
  2.  
  3. $result=mysql_query($dbQuery) or die("Could not get file list");
  4. // to display
  5. while($row=mysql_fetch_array($result))
  6. {
  7. ?>
  8. <tr>
  9. ..............
  10. <td><?php echo $row["phg1"]; ?></td>
  11. ...........
  12. </tr>
  13. }
[Please use CODE tags when posting source code. Thanks! --pbmods]

sure,,, it does not work, and I tried this way :

firstly , download .png files out from mysql to a local directory,
then display it using :

------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. $imagepath="/home/......1.png";
  2.  
  3. $image=imagecreatefromjpeg($imagepath);
  4.  
  5. header('Content-Type: image/png');
  6.  
  7. imagejpeg($image);                                                                                
-------------------------------------------------------

this does not work either.

anyone has good ideas about it ? please help . Thanks a million.

Tanya
Jun 1 '07 #1
Share this Question
Share on Google+
4 Replies


cyberking
P: 84
my .png files r stored as a blob in MySql,
I wanna to display them out in php through a web browser.

this is part of code (in php):

---after connect to database ,
$dbQuery=" select name, png1, png2 from png";

$result=mysql_query($dbQuery) or die("Could not get file list");
// to display
while($row=mysql_fetch_array($result))
{
?>
<tr>
..............
<td><?php echo $row["phg1"]; ?></td>
...........
</tr>
}

sure,,, it does not work, and I tried this way :

firstly , download .png files out from mysql to a local directory,
then display it using :

--------------------------------------------------------
$imagepath="/home/......1.png";

$image=imagecreatefromjpeg($imagepath);

header('Content-Type: image/png');

imagejpeg($image);
-------------------------------------------------------

this does not work either.

anyone has good ideas about it ? please help . Thanks a million.

Tanya
Hi,
Not very sure. I have never stored an image in a database. Always stored them on the local directory. Anyways, try doin this...

Once you finish querying your db,
Expand|Select|Wrap|Line Numbers
  1. while($row=mysql_fetch_array($result))
  2. {
  3. $image = $row['png'];
  4. }
  5.  
  6. <img src="<?php echo $image;?>">
[Please use CODE tags when posting source code. Thanks! --pbmods]
Try doing this. I think this 'll work.

Let me know,
Regards
CyberKing
Jun 1 '07 #2

P: 43
Hi,
Not very sure. I have never stored an image in a database. Always stored them on the local directory. Anyways, try doin this...

Once you finish querying your db,

while($row=mysql_fetch_array($result))
{
$image = $row['png'];
}

<img src="<?php echo $image;?>">
Try doing this. I think this 'll work.

Let me know,
Regards
CyberKing

Thanks for answering,

I tried, and got the same result with :
.................
Expand|Select|Wrap|Line Numbers
  1. <?php echo $row["phg"]; ?>
  2.  
.................
some unknown code come out.

Regards,
Tanya
Jun 1 '07 #3

cyberking
P: 84
Thanks for answering,

I tried, and got the same result with :
.................
<?php echo $row["phg"]; ?>
.................
some unknown code come out.

Regards,
Tanya
Hi

Ok, tell me onething. When you are ready to download the file from your database onto your server directory and then try all the jinx, why not store the file directly onto your server directory at the very first place??

Regards
CyberKing
Jun 1 '07 #4

P: 43
Hi

Ok, tell me onething. When you are ready to download the file from your database onto your server directory and then try all the jinx, why not store the file directly onto your server directory at the very first place??

Regards
CyberKing
Because my boss thought it was better to store pictures in database as a blob,
so I do the following......... but at last, we decided to store them in file system, which is quicker to display.
Yes , you are right.
anyway , thanks for answering.
Tanya
Jun 7 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.