Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Displaying image to IE problem

by Indomitus (Scribe)
on Mar 21, 2002 at 21:04 UTC ( [id://153423]=perlquestion: print w/replies, xml ) Need Help??

Indomitus has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to display an image from a non-web accessable directory to a webpage via the code that follows. My problem is that when I run the script in Internet Explorer, it tries to download the script and then when the script runs it tries to download the image. As a result I get 2 download windows instead of just one and the image doesn't display in the browser, it opens my local image display program. When I run the script in Mozilla or Netscape 4.7, it works fine, displaying the image in the browser with no problems. Is there any trick to doing this under IE (5.5 or 6)? I found some posts about IE and it's weird mime type behavior but nothing I thought was relevant to my problem. Was I wrong? Should I be doing the mime type stuff differently?

Here's the relevant code:
my $size = (-s $filename); # get extension for mime type $filename =~ m/\.([^.]+)$/; my $image_type = "image/$1"; print $cgi->header( -Content_Type => "$image_type", -Content_Disposition => "attachment; filename=$filename", -Content_Length => $size, -Expires => 'now', ); open(IMG, "<$filename") || die "Cannot open file: $!"; # not needed under linux ?? binmode(IMG); while( <IMG>) { print; }; close(IMG);
Thanks

Replies are listed 'Best First'.
(Ovid) Re: Displaying image to IE problem
by Ovid (Cardinal) on Mar 21, 2002 at 21:23 UTC

    Indomitus wrote:

    My problem is that when I run the script in Internet Explorer, it tries to download the script and then when the script runs it tries to download the image.

    I'm not sure I follow you. When using valid URL and you point your browser to a CGI, if the browser tries to download the script, this typically means that the Web server is not configured properly. In otherwords, it tries to send the script to the browser instead of executing it.

    What I read in your post is that the Web server is sending the script and also executing it?

    When I run the script in Mozilla or Netscape 4.7, it works fine, displaying the image in the browser with no problems.

    Now I'm even more confused. You have specified in your header that the content disposition is "attachment". This means that you should be prompted with a download dialog box. This shouldn't be automatically displaying.

    Side note:

    while( <IMG>) { print; };

    print takes a list (with an optional FH in front of it). Thus, you can do the following, which I think is cleaner:

    print <IMG>;

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

(cLive ;-)Re: Displaying image to IE problem
by cLive ;-) (Prior) on Mar 21, 2002 at 22:05 UTC
    I think you need to "fool" IE. When you call the script, add an image file extension to the end:
    http://www.site.com/cgi-bin/script.cgi?other=parameters&etc=etc&dummy= +image.jpg or add path info to the end http://www.site.com/cgi-bin/script.cgi/image.jpg

    At least, I *think* that was how I solved it...

    .02

    cLive ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://153423]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-09-08 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.