Database image display
[email protected] (Pedro Maló) Thu, 8 Jun 2000 23:45:09 +0100
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <[email protected]> |
My problem is this:
I have an image inside a database that I would like to display on the client
browser.
I've created a script that retrieves the data from inside the database.
Now the problem is how to send the image back to the browser.
I've come across with 2 solutions, one by the looking at the HTTP protocol
and another by searching the PHP manual.
-- 1st SOLUTION --
I've done a telnet to port 80 of a WWW server (both apache and IIS4) and
requested an image.
I've come to the conclusion that the server sends the image as it's binary
data without any headers.
Now, to implement this solution I need to instruct PHP not to send any
headers.
Sometime ago I have seen a thread message saying that it was **impossible**
to do it because of the nature of PHP (script engine), but for PHP installed
as a CGI.
In this cenario PHP is installed as a module both in apache and ISS4.
Now, is it possible to achive such a result?
-- 2nd SOLUTION --
In the PHP manual, under 'Creating GIF images' section is presented this
script:
<?php
Header("Content-type: image/gif");
$string=implode($argv," ");
$im = imagecreatefromgif("images/button1.gif");
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im)-7.5*strlen($string))/2;
ImageString($im,3,$px,9,$string,$orange);
ImageGif($im);
ImageDestroy($im);
?>
By looking at this I've come to the conclusion that it is an alternate way
of sending images back to the client.
Namely, by setting 'Content-type' I could send an image back to the client.
Now, I've created a script that sets such a header and then outputs all
binary data back to the client.
Under these conditions, the browser (IE5 or Netscape4.51) fails to display
the image, in such a way that keeps trying to retrieve more information from
the server, i.e., does not stop to download the page.
However, if I do a telnet to the server, the information is sent correctly
(header and image data) and the connection is closed by the server.
I've als tried to set the 'Content-Length' header to the image size, but the
result is the same.
Now, any clues on this?
Thanks in advance.
Pedro Miguel Negrao Malo | WWW: http://www.dee.fct.unl.pt/~pmm
E-mail: [email protected] | alternate E-mail: [email protected]
Phone: (+351+21)2948500 ext3740 | Fax: (+351+21)2957786
UNINOVA Institute | Inteligent Robotics Center
Faculty of Science and Technology | New University of Lisbon
2825 Monte Caparica | PORTUGAL
--
----
Help us to find alien civilizations, join SETI@home effort at
http://setiathome.ssl.berkeley.edu