Trouble Using a PHP Script to Send an Image

From: Michael J. Astrauskas (trevie_at_nospam.cox.net)
Date: 05/25/04


Date: Tue, 25 May 2004 10:42:31 -0700

I have a script, which I've called test-loadpic.php and some pages
reference it by means of

    <img src="test-loadpic.php?sourcepic=$picNum">

where $picNum stores a number. This part itself works fine.
test-loadpic.php uses the "sourcepic" GET variable to reference a file
on disk, get it's file/MIME type, transmit the headers and then the raw
image. The important code is below:

     header ("Content-type: $fileMIME");
     header ("Content-Length: ".filesize($filePath.$fileName));

     $fp = fopen ($filePath.$fileName, "rb");
     $er = fpassthru ($fp);
     fclose($fp);

$fileMIME is the MIME type of the image, of course ("image/gif" or
"image/jpeg" in my case). $filePath and $fileName point to the image
(ex: "/var/www/phptest/images/" and "filter.jpg").

Is this all I need to properly transmit an image?

This seems to work fine in IE but sometimes Netscape 7.1 tries to
download the image instead of showing it. Are my headers incorrect? I
suspect there's a glitch in my scripting that IE can tolerate but
Netscape can't. Is there a proper "end of image" code I need to send to
the browser that isn't included at the end of the images themselves?

Thank you in advance to anyone with some insight.

-- 
  - Michael J. Astrauskas


Relevant Pages

  • Re: window object
    ... Within a script, every reference to an object amounts to two ... calls from the scripting engine to the DHTML Object Model. ... var sText = document.all.div1.innerText; ...
    (comp.lang.javascript)
  • converting file dates into script variables
    ... a script was posted a few years ago that demonstrated the conversion ... of an IE favorites directory into a Netscape bookmarks.html file. ... Subject: IE Bookmarks into Netscape ... # Create some locals so we don't override the parent context. ...
    (comp.unix.shell)
  • Re: Decoupling javascript from UserControls
    ... still be able to reference the server-generated IDs. ... your server-side code emit a simple bit ofJavaScriptthat merely writes out ... (where JavaScriptSection is a Literal, ... generation in the markup and set vars as you mentionend in the Render ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Cross-Browser problems with Netscpae 7.0 & 4.72
    ... the transparency on the gifs may be working just fine. ... Unfortunately that means you're going to have to change your script and use ... Then I looked at it with Netscape 7.0 and my optimism was ... > onmouseover NOR onClick Javascript event triggers work. ...
    (microsoft.public.frontpage.client)
  • Re: IsValid(Object)
    ... > I have a complex problem involving a linked list, a scripted for-loop, a ... > reference to an object instance, ... > script commands that can arbitrarily modify the database. ...
    (borland.public.delphi.language.objectpascal)