Question:

Perl/CGI displaying images

by  |  earlier

0 LIKES UnLike

How do I display images with Perl CGI? I'm using the script below, but it's not working. When it is just the word "TEST" it is OK, but once I add the "<IMG SRC= . . . " it breaks.

Also, using the path below (substituting the actual site name) will display the image in a browser.

Help! What am I doing wrong??!

==========

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

use strict;

use integer;

use DBI;

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

print "

TEST<p>

<IMG SRC="

http://www.sitename.com/images/1.gif

">

";

 Tags:

   Report

1 ANSWERS


  1. This is one of those head-slap &quot;gee, I feel silly&quot; errors.  Notice that you have a print statement that&#039;s wrapped with double quotes?  And guess what you&#039;re using in the image tag-- more double quotes!

    Generally, I&#039;d recommend something like this:

    print qq`

    &lt;b&gt;Hello, &#039;$name&#039;, &amp; welcome&lt;/b&gt;

    &lt;img src=&quot;whatever.jpg&quot;&gt;

    `;

    That way, you can use whatever type of quotes you want! (in this case, the backtick symbol, which you probably don&#039;t use very often).  Otherwise, you can use double quotes, but escape any double quotes you&#039;d like to print:

    print &quot;

    &lt;b&gt;Hello, &#039;$name&#039;, &amp; welcome&lt;/b&gt;

    &lt;img src=\&quot;whatever.jpg\&quot;&gt;

    &quot;;

    DaveE

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.