in reply to Image display problem with CGI script

I think you probably want to do something like this:

print $cgi->header( -type=>'image/jpeg', -attachment=>$jpegFile); open( JPEG, $jpegFile ) || die "Unable to open $jpegFile for read: $!"; my $buffer; while ( sysread( JPEG, $buffer, 65536 ) ) { print $buffer; } close(JPEG);
--t. alex
Life is short: get busy!

Update: Corion and are disagree about whether a binmode is required .. anyone? Anyone?

Update 2: Corion pointed out that under Win32, binmode will be required .. but that's on the server, not on the client, since it's on the server that the CGI is being run. I forget that because I've been programming under Linux for the last five years -- binmode isn't required there.

Replies are listed 'Best First'.
Re: Re: Image display problem with CGI script
by Roger (Parson) on Dec 13, 2003 at 01:00 UTC
    Hi thanks talexb I think the problem is not with my script, but rather with my apache server, as I have just discovered. I invoked the cgi from another computer (other than the web server), I could see the images being properly displayed. Just that when I tried to access from the server box, the cgi hangs. So I am going to look a bit more into how my apache server was configured, hopefully that could give me more clue.

    I have tried to add the attachement option to my script, and it still not work from the server, but it works from a differnet computer with or without the attachment option.

    Thanks for the comment anyway. ;-)

Re: Re: Image display problem with CGI script
by Anonymous Monk on Dec 12, 2003 at 20:22 UTC

    Corion and are disagree about whether a binmode is required .. anyone? Anyone?

    Why? binmode can never hurt. Nothing will break if you add binmode when it's not needed, however, everything will break if you don't add it when it is.