Re: html display images without intermediate file

Vincent <[email protected]> Wed, 09 Apr 2014 19:17:24 +0200
Newsgroups gmane.comp.db.postgresql.php
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------040003050602020802030706
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 09-04-14 18:01, [email protected] wrote:
>
> Bonjour
> code working :
> $link = pg_Connect("host=localhost dbname=... user=... password='...'");
> $res = pg_query($link, "select miniature  from photo ");
> $numrows = pg_numrows($res);
> for($ri = 0; $ri < $numrows; $ri++) {
> $row = pg_fetch_array($res, $ri);
> $img =  pg_unescape_bytea($row['miniature']);
> $fln = "toto".$ri.".jpeg";
> file_put_contents($fln, $img);
> echo "<img src='".$fln."'/>";
> }
> How to do without the  intermediate file $fln ?
> Merci
The src in the img tag should point to a script that fetches the image, 
see header() in the PHP manual.

But you probably should not do that, because it is very slow and loads 
the database up with tasks that it should not do.
Keep images as files on disk, that is *much* faster.

--------------040003050602020802030706
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 09-04-14 18:01, <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
      wrote:<br>
    </div>
    <blockquote
      cite="mid:[email protected]"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <br>
      <div class="inbox" style="margin: 0px; padding: 0px 0px 1px;
        list-style: none; min-height: 1px; color: rgb(51, 51, 51);
        font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
        11px;">
        <div class="postbody" style="margin: 0px; padding: 0px;
          list-style: none;">
          <div class="postright" style="margin: 0px; padding: 6px;
            list-style: none; border-left-width: 18em;
            border-left-style: solid; background-color: rgb(222, 223,
            223); border-left-color: rgb(241, 241, 241); position:
            static; z-index: auto;">
            <div class="postmsg" style="margin: 0px; padding: 0px;
              list-style: none; overflow: hidden; width: 806px;">
              <div style="margin: 0px; padding: 0px; list-style: none;
                line-height: 1.4;">Bonjour</div>
              <div style="margin: 0px; padding: 0px; list-style: none;
                line-height: 1.4;">code working :<br>
                $link = pg_Connect("host=localhost dbname=... user=...
                password='...'");<br>
                $res = pg_query($link, "select miniature&nbsp; from photo ");<br>
                $numrows = pg_numrows($res);<br>
                for($ri = 0; $ri &lt; $numrows; $ri++) {<br>
                $row = pg_fetch_array($res, $ri);<br>
                $img =&nbsp; pg_unescape_bytea($row['miniature']);<br>
                $fln = "toto".$ri.".jpeg";<br>
                file_put_contents($fln, $img);<br>
                echo "&lt;img src='".$fln."'/&gt;";<br>
                }</div>
              <div style="margin: 0px; padding: 0px; list-style: none;
                line-height: 1.4;">How to do without the &nbsp;intermediate
                file $fln ?</div>
              <div style="margin: 0px; padding: 0px; list-style: none;
                line-height: 1.4;">Merci</div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    The src in the img tag should point to a script that fetches the
    image, see header() in the PHP manual.<br>
    <br>
    But you probably should not do that, because it is very slow and
    loads the database up with tasks that it should not do.<br>
    Keep images as files on disk, that is *much* faster.<br>
  </body>
</html>

--------------040003050602020802030706--