How to display .png file from MySql in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tanyali
    New Member
    • Feb 2007
    • 43

    How to display .png file from MySql in php?

    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 , [code=php]
    $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>
    }[/code]

    [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 :

    ------------------------------------------------------
    [code=php]
    $imagepath="/home/......1.png";

    $image=imagecre atefromjpeg($im agepath);

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

    imagejpeg($imag e); [/code]
    -------------------------------------------------------

    this does not work either.

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

    Tanya
    Last edited by pbmods; Jun 1 '07, 04:33 PM. Reason: Added code tags.
  • cyberking
    New Member
    • Jan 2007
    • 84

    #2
    Originally posted by tanyali
    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,
    [code=php]
    while($row=mysq l_fetch_array($ result))
    {
    $image = $row['png'];
    }

    <img src="<?php echo $image;?>">[/code]
    [Please use CODE tags when posting source code. Thanks! --pbmods]
    Try doing this. I think this 'll work.

    Let me know,
    Regards
    CyberKing
    Last edited by pbmods; Jun 1 '07, 04:34 PM. Reason: Added code tags.

    Comment

    • tanyali
      New Member
      • Feb 2007
      • 43

      #3
      Originally posted by cyberking
      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 :
      ............... ..
      [code=php]
      <?php echo $row["phg"]; ?>
      [/code]
      ............... ..
      some unknown code come out.

      Regards,
      Tanya

      Comment

      • cyberking
        New Member
        • Jan 2007
        • 84

        #4
        Originally posted by tanyali
        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

        Comment

        • tanyali
          New Member
          • Feb 2007
          • 43

          #5
          Originally posted by cyberking
          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

          Comment

          Working...