pdl_babu has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: <img> is not displaying images
by Corion (Patriarch) on Oct 21, 2005 at 06:30 UTC

    You don't give us much to work with here. Please look in your web server error logs for the error message that the server creates. What error response do you get when you try to display the image directly in your browser? Please read How (not) to ask a question to learn more about how to get useful answers.

    My first three guesses are:

    • The htdocs location is not served by the webserver as /htdocs but is served as the web root /.
    • Your webserver is not configured to execute CGI scripts in the htdocs/test location.
    • Your script does not output a valid JPEG image.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: <img> is not displaying images
by Skeeve (Parson) on Oct 21, 2005 at 06:30 UTC

    Is that a Perl-question?

    look into apache's error and access log to find out what's happening. Or use a network sniffer to see whether or not your browser asks for that image.


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: <img> is not displaying images
by svenXY (Deacon) on Oct 21, 2005 at 08:28 UTC
    Hi,
    for a start (and given you work with Linux), open a teminal and type
    tail -f /var/log/httpd/error_log
    or wherever Apache logs to on your machine.
    Then reload your cgi in the browser.
    You should now see the error message you normaly see when using command line scripts.

    Also, as Corion already pointed out, htdocs is usually the DocumentRoot of your Apache server, so you need to start your absolute path after the htdocs (in your case probably <img src="/test/DailyReport.jpg">
    Regards,
    svenXY
Re: <img> is not displaying images
by inman (Curate) on Oct 21, 2005 at 08:36 UTC
    Try using either Mozilla or Firefox with the Live HTTP Headers plugin to work out what your browser is asking for. When you load the page, the HTTP requests for all resources on the page will be recorded by the Live Headers plugin.

    In general you should:

    1. Check that your script is creating the correct HTML for the img tag.
    2. Take the img source and us it with the page URL to investigate whether there is a problem server side.
    3. Use Live Headers to investigate the transaction looking for things that are not related to the HTML such as cookies etc.

    My bet is that the source of your image tag refers to a resource that isn't there. E.g. your script is running as http://localhost/cgi-bin/myscript.cgi and the browser is creating the URL http://localhost/cgi-bin/htdocs/test/DailyReport.jpg for your image. I reckon that this isn't what you want.

Re: <img> is not displaying images
by cbrandtbuffalo (Deacon) on Oct 21, 2005 at 12:41 UTC
    The simple case is that the image just isn't there. To try to poke at just the image, put the site address and your path into a browser and see if it will display the image when you request it directly. For example http://my.site.org/htdocs/test/DailyReport.jpg. If you don't see the image, start troubleshooting from there.

    First look on the file system and verify that the image is there. Make sure the file has a non-zero size, which means there is an actual image there. If it's on the file system somewhere, you just need to figure out how to get to it. Play around with the path in your browser. When you get it right, fix the CGI script.

Re: <img> is not displaying images
by Delusional (Beadle) on Oct 21, 2005 at 13:54 UTC
    Perhaps you can take a browser approch. You are passing img to the browser, and the browser should execute it (provided your allowing the browser to load images).

    If the site URL is http://127.0.0.1 and the image is htdocs/test/DailyReport.jpg, then open your browser and enter http://127.0.0.1/htdocs/test/DailyReport.jpg . If you don't get an image (i.e. error 404 file not found), then the url your passing is wrong. Look at where the server is serving from and use virtual locations verses hard coded locations. Chances are, you will have better luck that way.

    More then likely, the browser is looking in the wrong location for the image and should be looking at http://127.0.0.1/test/DailyReport.jpg or http://127.0.0.1/DailyReport.jpg .
Re: <img> is not displaying images
by blazar (Canon) on Oct 21, 2005 at 08:27 UTC
    Granted that I fail to understand which is the perl question here, if you're using CGI.pm as you definitely should, and if you're using its header()'s default settings, then you're serving XHTML 1.0 Transitional; so I haven't the slightest idea whether this may have to do with the problem you're experiencing, but the above should be
    <!-- <img src="htdocs/test/DailyReport.jpg"> --> <img src="htdocs/test/DailyReport.jpg" />
    of course CGI.pm itself would take care of this as long as you
    print img { src => $DRurl, alt => "[Daily Report]" };

    Update: fixed a typo according to dorward's reply.

      XHTML 1.0 Transitional requires an alt attribute on all images, and if you plan to serve it as text/html (thus making the choice of XHTML pointless but allowing "older" browsers (like GoogleBot and Internet Explorer 7) to cope) then Appendix C requires a space before the "/" at the end.

      <img src="htdocs/test/DailyReport.jpg" alt="Suitable Text alternative" />