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

I need to open a .gif or .jpg file and print it to the browser called from an img tag. I can't use a redirect because the image will be in a directory not viewable by the public. (Not in the public_html dir.)

HTML File:
<img src="image.pl">

image.pl:

#!/usr/bin/perl -wT use strict; open(IMAGE, "x.gif") || error_stuff(); print "Content-type: image/gif\n\n" . <IMAGE>; close(IMAGE);

Is there a better way to do this?

Thanks
Joshua

Replies are listed 'Best First'.
Re: Printing an Image From a File to the Browser...
by dws (Chancellor) on Jun 14, 2002 at 23:42 UTC
    You're probably getting tripped up by   print "Content-type: image/gif\n\n" . <IMAGE>; which is going to give you the first "line" of the image. The concatenation operator forces scalar context onto <IMAGE>, which isn't what you want.
    print "Content-type: image/gif\n\n"; binmode(IMAGE); print <IMAGE>;
    should do it for you. (I threw in the binmode() in the unlikely event that you're running on Win32.)

      I threw in the binmode() in the unlikely event that you're running on Win32.

      God Forbid! :)

      Joshua

Re: Printing an Image From a File to the Browser...
by r0b (Pilgrim) on Jun 14, 2002 at 23:25 UTC
    Try Print Image File and display gif image.

    ~~rob
    ____________________________________________________________
    eval pack "h*", "072796e647022245d445f475454494c5e622b3";

A reply falls below the community's threshold of quality. You may see it by logging in.