473,466 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to display .png file from MySql in php?

43 New Member
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
4 6633
cyberking
84 New Member
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
tanyali
43 New Member
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
84 New Member
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
tanyali
43 New Member
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

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

Similar topics

7
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
0
by: Frlo | last post by:
Hi, I have problem that I tried to solve but i missed out. My situation: I have problem that my page www.vodotika.sk display some wrong characters. Apache server 2.0.54 runs on windows-1250...
2
by: Stephen Harris | last post by:
I downloaded: Windows Binaries PHP 5.0.4 zip package - 31 Mar 2005 md5: fff10991a8e6f3b36ee567eb236ae3f4 This is the current BETA release of version 5.0 of the MySQL database server....
0
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display....
2
by: david | last post by:
Hi, I have asp pages running from a MySQL database. I have placed a path in the required field (although not quite sure on the correct format). My asp page is just displaying the text path...
6
by: Mark | last post by:
Hello all, I have the following file.txt storing these kind of values: Name: John Doe E-mail: john@doe.com Phone: 555 865 8901 Address: 71 Huntington Ln. (33444) FL - Delray Beach US Member...
1
by: Objectifnet | last post by:
What I really want to do is to be able to link two pages together using an ID, The table involved displays an image stored on the File Server that has the image details stored in the Database called....
9
by: tomhawkins1 | last post by:
Hi I currently have a site where users can upload files. These files can be doc, wmv, jpeg, xls, dwf, dwf and dwg. These files are uploaded to /home/**user**/uploads and not /home/...
7
by: iahamed via WebmasterKB.com | last post by:
Hi all, I need to display records Horizontally, I do not know for some reason this code gives me an error, uses an access db. Microsoft VBScript compilation (0x800A040E) 'loop' without 'do'...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.