How can I access an image from mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ricki Susic

    How can I access an image from mysql

    Hi,

    I have this script:

    <?php
    mysql_connect(" host", "user", "pass");

    mysql_select_db ("database") ;

    $query = "select * from table";
    $result = MYSQL_QUERY($qu ery);
    while($myrow=my sql_fetch_array ($result)){
    echo "<img src=".$myrow['bin_data']."><br>";
    };


    ?>

    I can't get the output from the "bin_data" to show as an image ( which it
    is ).
    Can anyone tell me what's wrong?

    Ricki


  • Matthias Gutfeldt

    #2
    Re: How can I access an image from mysql

    Ricki Susic wrote:[color=blue]
    > Hi,
    >
    > I have this script:
    >
    > <?php
    > mysql_connect(" host", "user", "pass");
    >
    > mysql_select_db ("database") ;
    >
    > $query = "select * from table";
    > $result = MYSQL_QUERY($qu ery);
    > while($myrow=my sql_fetch_array ($result)){
    > echo "<img src=".$myrow['bin_data']."><br>";
    > };
    >
    >
    > ?>
    >
    > I can't get the output from the "bin_data" to show as an image ( which it
    > is ).
    > Can anyone tell me what's wrong?[/color]

    You have to send the correct MIME Type header.


    Matthias

    Comment

    • Geoff Berrow

      #3
      Re: How can I access an image from mysql

      I noticed that Message-ID: <bnobst$u4kd6$2 @ID-16734.news.uni-berlin.de>
      from Matthias Gutfeldt contained the following:
      [color=blue][color=green]
      >> $result = MYSQL_QUERY($qu ery);
      >> while($myrow=my sql_fetch_array ($result)){
      >> echo "<img src=".$myrow['bin_data']."><br>";
      >> };
      >>
      >>
      >> ?>
      >>
      >> I can't get the output from the "bin_data" to show as an image ( which it
      >> is ).
      >> Can anyone tell me what's wrong?[/color]
      >
      >You have to send the correct MIME Type header.[/color]

      I find it easier to store the image elsewhere and just save the path in
      the db.

      --
      Geoff Berrow
      It's only Usenet, no one dies.
      My opinions, not the committee's, mine.
      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

      Comment

      • Matthias Gutfeldt

        #4
        Re: How can I access an image from mysql

        Geoff Berrow wrote:[color=blue]
        > I noticed that Message-ID: <bnobst$u4kd6$2 @ID-16734.news.uni-berlin.de>
        > from Matthias Gutfeldt contained the following:
        >
        >[color=green][color=darkred]
        >>> $result = MYSQL_QUERY($qu ery);
        >>> while($myrow=my sql_fetch_array ($result)){
        >>> echo "<img src=".$myrow['bin_data']."><br>";
        >>> };
        >>>
        >>>
        >>>?>
        >>>
        >>>I can't get the output from the "bin_data" to show as an image ( which it
        >>>is ).
        >>>Can anyone tell me what's wrong?[/color]
        >>
        >>You have to send the correct MIME Type header.[/color]
        >
        >
        > I find it easier to store the image elsewhere and just save the path in
        > the db.[/color]

        Me too. But that's not what he's doing.


        Matthias


        Comment

        • Ricki Susic

          #5
          Re: How can I access an image from mysql

          >You have to send the correct MIME Type header.[color=blue]
          >Matthias[/color]


          Can you tell what that is?

          Ricki


          Comment

          • kilian

            #6
            Re: How can I access an image from mysql

            Hello,

            To use an image, you nead a header-information.
            You can't create an image in a file you are using.
            Just use an other file that takes the image-data and sets a header
            like "header("Conten t-Type: ...");

            Than you can use the image by using filename.php?im g=DB-ID

            sorry, my english is not very good :)

            Kilian

            Comment

            • Matthias Gutfeldt

              #7
              Re: How can I access an image from mysql

              Ricki Susic wrote:[color=blue][color=green]
              >>You have to send the correct MIME Type header.
              >>Matthias[/color]
              >
              >
              >
              > Can you tell what that is?[/color]

              The important thing to note about image creation: The PHP code that
              creates the image has to be in a file on its own, which is then called
              from the page: <img src="php-created-image.php">. You can't "echo" the
              image date right into the src attribute.

              Check the PHP manual: <http://ch.php.net/manual/en/ref.image.php>.
              There's a simple example for a PNG graphic, and an explanation how to
              use it.


              Matthias

              Comment

              Working...