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:
Add gif to perl code

 



mmcw
User

May 7, 2001, 6:26 AM

Post #1 of 6 (805 views)
Add gif to perl code Can't Post

I have a very bog script.
This script will return a gif image.

print "Location: test.gif\n\n";
exit;

Is it possible to include the gif code into the perl code so I do not have to upload the test.gif image
to my server but only the perl script?

I want to reduce the file to be uploaded to the server!!



Kanji
User

May 7, 2001, 8:14 PM

Post #2 of 6 (797 views)
Re: Add gif to perl code [In reply to] Can't Post

Yes. You can do it a variety of ways, but I would suggest placing the .GIF's contents after a __END__ or __DATA__ tag in your script and then doing something like ...


Code
if ( $ENV{'PATH_INFO'} eq "/test.gif" ) { 
print "Content-Type: image/gif\n\n";

binmode(DATA); # Just in case
print while <DATA>;
exit;
}



mmcw
User

May 9, 2001, 3:05 AM

Post #3 of 6 (792 views)
Re: Add gif to perl code [In reply to] Can't Post

I have tried this (without success)

#!/usr/local/bin/perl -w

print "Content-Type: image/gif\n\n";
binmode(DATA); # Just in case
print while <DATA>;
exit;

__DATA__
GIF89a' . ...!!!)))111UUUsss!.. . , ' . .I8cXKDh.@B>.)jM@ɍ;g..lH8t@OR1.j<S.0:
.p./·ƱKF,dK..d6..K.
ulb .Sy.
.j. b.|,3

Z ..
.
..3
..Y ..#(. wd*-. ..r..ķ)....:WU)W.Ld.J..,m. .0 .. .2.. .+..)
2...%W2}.QXA.D...݊K.9.פܔ.?oRpib
F .JB
.(..$A ..H,f4 4a9... .Jph. ;



I have attached the image I want to use!




rjoseph
Novice

May 9, 2001, 9:56 AM

Post #4 of 6 (790 views)
Re:Add gif to perl code---------------------------7d13d41f58c<br>Content-Disposition: form-data; name=&quot;Icon&quot;<br><br>book.gif [In reply to] Can't Post

OK, you can't read a GIF image in ASCII mode - GIF images are binary files, they must be read in binary mode.

Because you 'attached' the file to the end of the script, it is probably already in ASCII mode anyway, so it probably wont display, but to read it from the data from the DATA handle safely (if in fact it is still in binary mode, which I doubt):

Code
binmode(DATA); 
while(<DATA>) { # your gif image... }

Make sure the file is read in binmode, although I would suggest making the file an external, binary file :)

Hope this helps!

r j o s e p h
"Violence is a last resort of the incompetent" - Foundation


mmcw
User

May 10, 2001, 6:41 AM

Post #5 of 6 (778 views)
Re:Add gif to perl code---------------------------7d13d41f58c<br>Content-Disposition: form-data; name="Icon"<br><br>book.gif [In reply to] Can't Post

I have tried to upload it in binary mode also.
I got an error 500!!
Whats is wrong??




Kanji
User

May 10, 2001, 9:02 PM

Post #6 of 6 (769 views)
Re:Add gif to perl code [In reply to] Can't Post

Have you taken a look at your error logs to see why it is giving you a 500 error?

Also, how are you adding the code to the .GIF (or vice-versa)? Perhaps your editor is not saving the file correctly?



 
 


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

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