CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
"Fun" with images



Oct 14, 2001, 11:03 AM

Post #1 of 3 (622 views)
"Fun" with images Can't Post

I'm trying to make a program that password-protects images on a webpage my having them a directory higher than that to which the URL points. Seemed simple enough, just grab the data and toss it out, byte by byte. Here's the code I came up with:

#!/perl/bin -w
print "Content-type:image/gif\n\n";
open (GIF,"images/nato.gif");
binmode GIF;
while (sysread(GIF, $buffer, 1)){ print $buffer; }
close GIF;

However, it's only giving me part of the file and it's corrupting what it's giving me, too.

Program -
Image -

What's causing the problems? It seems strait forward enough...

Enthusiast / Moderator

Oct 14, 2001, 11:38 AM

Post #2 of 3 (621 views)
Re: "Fun" with images [In reply to] Can't Post

You need to binmode standard output, too. I had the same problem just yesterday as an ftp download corrupted a bzipped archive. Fortunately I had Perl to s/\r\n/\n/g the file, and when I used exactly that on your corrupted gif, it looked pretty good. Wink
For efficiency reasons, you might prefer the following script that reads/prints the whole file as one big block:

#!/perl/bin -w 
open GIF, 'images/nato.gif' or die "nato.gif: $!\n";
binmode GIF;
binmode STDOUT;
undef $/;
print "Content-type:image/gif\n\n", <GIF>;
close GIF;

Hope this helps.

-- Marcus



Oct 15, 2001, 12:02 AM

Post #3 of 3 (615 views)
THANK YOU! [In reply to] Can't Post

I've been looking all over for that answer. Bless you with health, happiness, and hoards of hot guys and/or girls (whichever you prefer) hanging over you for the rest of your days!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives