CGI and PERL help - no image

Discussion in 'Perl Misc' started by secSwami, Nov 26, 2008.

  1. secSwami

    secSwami Guest

    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
    secSwami, Nov 26, 2008
    #1
    1. Advertising

  2. secSwami

    Guest

    secSwami <> wrote:
    > 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.
    , Nov 26, 2008
    #2
    1. Advertising

  3. secSwami

    secSwami Guest

    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




    wrote:
    > secSwami <> wrote:
    >> 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
    >
    secSwami, Nov 26, 2008
    #3
  4. secSwami

    secSwami Guest

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

    thx

    wrote:
    > secSwami <> wrote:
    >> 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
    >
    secSwami, Nov 26, 2008
    #4
  5. [ Please do not top-post! ]


    secSwami <> wrote:


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


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Nov 26, 2008
    #5
  6. secSwami <> wrote:
    >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
    Jürgen Exner, Nov 26, 2008
    #6
  7. Sherm Pendley, Nov 26, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,253
    Jürgen Exner
    Jul 31, 2003
  2. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    533
    Michael Sparks
    Jul 30, 2005
  3. excord80
    Replies:
    17
    Views:
    632
    J Kenneth King
    Jan 29, 2009
  4. joe
    Replies:
    7
    Views:
    147
    Joseph
    May 12, 2004
  5. kath
    Replies:
    4
    Views:
    561
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page