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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



Psudo
stranger

Oct 14, 2001, 11:03 AM

Post #1 of 3 (534 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.

Example:
Program - http://208.186.104.108/temp.pl
Image - http://208.186.104.108/images/nato.gif

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



mhx
Enthusiast / Moderator

Oct 14, 2001, 11:38 AM

Post #2 of 3 (533 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:

Code
#!/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


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



Psudo
stranger

Oct 15, 2001, 12:02 AM

Post #3 of 3 (527 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