473,946 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
+ 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 6665
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_q uery($dbQuery) or die("Could not get file list");
// to display
while($row=mysq l_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=imagecre atefromjpeg($im agepath);

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

imagejpeg($imag e);
-------------------------------------------------------

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=mysq l_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
3372
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. This question might be more suited to a MySQL newsgroup, but since php and MySQL seem to have become almost married to one another, and since getting the data out and displaying it is where my problem seems to lie, I thought I would start with...
0
1484
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 character set, same as php page was written in, and the dump file for mysql database has same codepage cp1250. The Mysql SHOW SESSION VARIABLES; looks like: | character_set_client | cp1250
2
2192
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. apache_2.0.54-win32-x86-no_ssl.exe 16-Apr-2005 15:13 7.8M Installer Pack
0
1445
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. From doing weird alignment things, to making it so that so long as those characters are visible, the display is always scrolled to a line where one of those screwy ASCII characters are. I can scroll up or down, but as soon as I type something on...
2
2287
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 instead of the image. I'm using response.write. The Folder is called : images
6
2313
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 ID: 373732510149005 Registration date: 5/2005
1
2344
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. THE Database used is MySQL "Support" on a Table Called "profiles": The problem is how do I get this piece of codes to link to a details page called "PATRONS_DETAILS.PHP" and display information about one particular database detail. With ID...
9
2087
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/ **user**/public_html/uploads to prevent any old user from browsing them. I then use a general showDoc page with the following function (from
7
1950
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' /aspcodes/DisplayROwsHorizon/index.asp, line 26 Loop
0
10151
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9977
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11556
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11332
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10684
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7412
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6325
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4933
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.