Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Printing an Image From a File to the Browser...

by joshua (Pilgrim)
on Jun 14, 2002 at 23:15 UTC ( [id://174746]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-24 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found