faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

89 of 148 people (60%) answered Yes
Recently 4 of 10 people (40%) answered Yes


How can I use PHP to return an image?
What HTTP headers do I need to set to return an image from PHP?
How can I store images in a Postgres database?
in Non_Server Client Site to get a variable from Server Client Site e.g. HTML get a result from PHP

Mar 15th, 2008 21:30
dman, ha mo, Nathan Wallace, John Leung, http://www.ttnr.org

A request for an image is a separate HTTP request.
In essence, an image is its own web page.
You need to write a script to output *JUST* the image.
And another to provide the page/author/etc.
Here is an example that returns an inmage and it's information from a
Postgres database:
        $news = pg_Exec($conn,"select text_id, 
                               from tblcontent");
        $newscount = 0;
        while (list($name, $email, $date, $blurb, $ctobj) = 
                   @pg_fetchrow($news, $newscount)) {
            echo $name, ' ', $email, ' ', $date, "<BR>\n";
            echo $blurb, "<BR>\n";
            echo "<IMG SRC=image.php3?display_num=$ctobj>";
            $newscount  ;
      $fhandle = pg_loopen($conn,$ctobj,"r");
      $img1 = pg_loreadall($fhandle);
      $size = pg_loread($fhandle);
      header("Content-type: image/jpg");
      header("Content-length: $size);
      header("X-Image-ID: $ctobj);
      echo $img1;