Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: <img> tag does not work in my perl/cgi code

by jkva (Chaplain)
on Feb 23, 2008 at 21:49 UTC ( #669771=note: print w/ replies, xml ) Need Help??


in reply to <img> tag does not work in my perl/cgi code

Just a wild guess... but I'd say your webserver is configured to treat files in /cgi-bin as scripts and can therefore not show it. But I might be completely wrong. In any case, cgi-bin is for scripts, not for images. Those belong in another folder , depending on your webserver's configuration.

Best of luck!


Comment on Re: <img> tag does not work in my perl/cgi code
Re^2: <img> tag does not work in my perl/cgi code
by vit (Pilgrim) on Feb 23, 2008 at 22:16 UTC
    Thanks, it's a good guess, I will try to see the server configuration. The only thing is that I store other files like click count and others under /cgi-bin/ and all of them work. Could you comment this.
      It really depends on which program is in control when you are trying to look up /images/image.png. Sometimes /images/image.png is a URL, and sometimes it is a file path, and the two are most definately different, even though they look the same.

      Apache handles this internally, using a complex set of rules. /cgi-bin/ is one of these rules. Instead of looking in /var/www/cgi-bin/, Apache looks in /usr/lib/cgi-bin/ (under Debian). /images/ can be remapped in Apache too, perhaps leading to /var/images or something like that.

      However once your perl script has started, path lookups are handled as normal Unix path lookups (using the system PATH variable, plus any changes depending on the users settings).

      This is confusing, difficult, undocumented and something you have to learn when dealing with Unix. Or any operating system really. Web services are a confusing mash of programs, and figuring out which one has control at the critical moment is a big part of figuring out the bugs.

      ___________________
      Jeremy
      Insight is found at the bottom of the cup.

      Dear Guys,

      I'm New to PERL, I'm trying to create a webpage with a Logo in PERL+CGI.

      I'm also facing the same problem.

      If you solved this, please share the information to help me.

      Here is my code:

      #!C:/Perl/bin/perl.exe use CGI; $q = new CGI; print "Content-type:text/html\n\n"; print '<HTML> <head></head> <body> <h1> <img alt="LOGO" src="LOGO.gif" alt="LOGO"/> My Name is SaRaVaNaN. </h1> </body> </HTML>';

      The HTML Styles are loading perfectly, & a 'X' box is showing instead of the image.

        There ain't no PERL. The language is spelled "Perl", the script interpreter is spelled "perl".

        Right-Click on the broken ("X") image and select "properties". Look at the image's URL. I could bet that you don't load the image from where you want to load it. With your code, and a typical CGI mapping set up on the web server, and no PATH_INFO in your URL (i.e. your URL ends with the script's name), the file LOGO.gif must reside in the same directory as your Perl CGI script. This is possible, but unusual. Most web servers don't allow static resources inside the CGI directories, and typically return an error page for those files. Copy the image's URL into the address line of a new browser window and look for yourself.

        To fix that problem, either move the image into a directory from which static resources are served, and use a proper URL in the "src" attribute of the "img" tag; or switch from the dedicated CGI directory to CGIs inside the "normal" directories, detected by the file extensions. (For Apache: switch from "ScriptAlias" to "AddHandler cgi-script".)

        Looking at your shebang line, it looks like you are running Windows, which can add some strange effects, too. But for this trivial case, Windows does not hurt.

        Oh, and you don't have to write all HTML by yourself, the CGI module offers a nice syntax for creating HTML, and if you want to separate program logic (Perl) and presentation (HTML) -- which you really should, except for tiny throw-away scripts -- you should use a template engine like Template Toolkit.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://669771]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-10-23 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls