CGI and PERL help - no image

S

secSwami

I am messing around with cgi and perl. I have a cgi page test.cgi with
following code:

#!/usr/bin/perl

print "<html>
<head>
<title>TEST CAPTCHA IMAGE Verification</title>
</head>

<body>
<img src=\"/cgi-bin/test3.cgi\">
</body>
</html>";

As you can see I am calling test3.cgi as my image. Here is my code in
test3.cgi :

#!/usr/bin/perl
use CGI;

print header;
print "Content-type: image/gif\n\n";
print "<img src=\"/images/angry.gif\">";




When I try opening up test.cgi, I don't get ANY IMAGE outputted to my
browser.

Can anyone point me what is wrong with my script??

Thx in advance
 
X

xhoster

secSwami said:
I am messing around with cgi and perl. I have a cgi page test.cgi with
following code:

#!/usr/bin/perl

print "<html>
<head>
<title>TEST CAPTCHA IMAGE Verification</title>
</head>

<body>
<img src=\"/cgi-bin/test3.cgi\">
</body>
</html>";

You aren't printing a response header. That might be a problem. Then
again, it might not.

More importantly, you aren't using "use strict" and "use warnings", which
will catch many errors for you. The first thing you should do is ask Perl
to help you, by including use strict and use warnings.

As you can see I am calling test3.cgi as my image. Here is my code in
test3.cgi :

#!/usr/bin/perl
use CGI;

print header;

What do you expect this to do? Are you sure it is doing it?
print "Content-type: image/gif\n\n";

How do you think this will interact with the previous line?
print "<img src=\"/images/angry.gif\">";

You told it that the content type was an image/gif, but now you are sending
it html, which is not image/gif.
When I try opening up test.cgi, I don't get ANY IMAGE outputted to my
browser.

So, what *do* you see? A broken image icon? A 500 error?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
S

secSwami

Thanks Xho for quick reply, while i was trying to get this going I was
trying too many things that is why the code is out of whack but here is
a good example of what I am doing now and its the same result (NO IMAGE).

call_image.cgi:

#!/usr/bin/perl -wT

print "Content-type: text/html\n\n";

print "<HTML>
<BODY>
<IMG SRC=\"show_image.cgi\">
</BODY>
</HTML>" ;



show_image.cgi:

#!/usr/bin/perl -wT

print "Content-type: image/gif\n\n";
print "<img src=\"angry.gif\">";



The image resides in the same directory as all the cgi scripts.

This is part of bigger code that I am writing to display CAPTCHA images
but for some reason I cannot get the image rendered on the "call_image.cgi"

fyi: I am on a macbook and using macports version on apache. Not the
one that comes built in.

Thanks for your help.

-Parvinder Bhasin
 
S

secSwami

For your last question: I get broken image (no image, question mark box
in safari). No 500s.

thx
 
T

Tad J McClellan

[ Please do not top-post! ]


#!/usr/bin/perl -wT


#!/usr/bin/perl -T
use warnings;
use strict;

print "Content-type: image/gif\n\n";
print "<img src=\"angry.gif\">";



The image resides in the same directory as all the cgi scripts.


That does not matter.

What *does* matter is where they reside relative to your current
working directory (which may not be where the scripts live).

This is part of bigger code that I am writing to display CAPTCHA images
but for some reason I cannot get the image rendered on the "call_image.cgi"
^^^^^^^^^^^^^^^

You have already been given the reason:

You told it that the content type was an image/gif, but now you are sending
it html, which is not image/gif.

Modify show_image.cgi so that it outputs an image file rather
than outputting HTML.


[ snip upside-down quoting ]
 
J

Jürgen Exner

secSwami said:
print "Content-type: image/gif\n\n";
print "<img src=\"angry.gif\">";

I may be be wrong but to me this
<img src="angry.gif">
looks like text or maybe an HTML snippet but by no means like an image
in gif as claimed by your content type.

Your question has nothing to do with HTML.
Had you written your CGI script in C or Haskell, you would have exactly
the same problem.

jue
 
S

Sherm Pendley

secSwami said:
#!/usr/bin/perl
use CGI;

print header;
print "Content-type: image/gif\n\n";
print "<img src=\"/images/angry.gif\">";

Your script is sending HTML, not a GIF image.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top