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

I am trying to display an image in my script. The problem is that the script can't find the image. I've tried the following codes:
print "<IMG SRC=$courselocation/images/$value>"; print "<IMG SRC=\"$courselocation/images/$value\">"; print "<IMG SRC=/$courselocation/images/$value>"; print img(-name=>'image', -src=>'$courselocation/images/$value');
and others. (I don't get any error messages or log errors so if I've mistyped anything here its a local error here) I have printed out the variables and they appear to be fine. $courselocation prints as ist001 and $value prints as newlogotr.gif. My root directory is
novonyx/suitspot/docs/perlroot. The courselocation is a subdirectory of this. I derived $courselocation from doing the following:
$courselocation = substr($file, 0, 6); where $file = ist001/quiz1.txt.
$value is read from a text file which looks like this: i1:newlogotr.gif~
I've even hardcoded the location in the script like this:
print "<IMG SRC=novonyx/suitspot/docs/perlroot/ist001/images/newlogotr +.gif>"; print "<IMG SRC=/novonyx/suitspot/docs/perlroot/ist001/images/newlogot +r.gif>"; print "<IMG SRC=\"novonyx/suitspot/docs/perlroot/ist001/images/newlogo +tr.gif\">";
In every case the little square box appears where the image is supposed to be, but no image. I've checked and double checked spelling, syntax, etc. I tried it at home using:
<img src=$value>
where $value = images/newlogotr.gif and it worked fine. At work I'm using perl 5.? but its not 5.6 which is what I'm using at home. I didn't know if 5.6 handled images differently or not. I suspect the problem is with my server. I guess what I'm asking for is any other troubleshooting ideas you might be able to provide. I've run out of ideas.
Many thanks. Chris

Replies are listed 'Best First'.
Re: displaying an image
by little (Curate) on Jan 17, 2002 at 18:16 UTC
    In your browser rightclick the image, choose properties and take a look at the URI of the image, then compar ethat to the location you wnated to specify.
    You might use string concatenation using . eg.:
    print '<IMG SRC="'.$courselocation.'/images/'.$value.'">';
    Further turn on wanrings using -w in your script and see if you get errors, which you please post here as well.
    Have a nice day
    All decision is left to your taste
Re: displaying an image
by Masem (Monsignor) on Jan 17, 2002 at 19:40 UTC
    Also, in addition to the programming solutions, check to make sure that the permissions for the image are correct. All directorys above the image need at least +rx for the http application user or group, and the image itself needs to be +r. To check, you can type the URL of the image directly into the browser, and see if it finds it. Also check the source of the resulting web page to make sure that it looks correct as well.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

Re: displaying an image
by newbie00 (Beadle) on Jan 17, 2002 at 18:12 UTC
    During your troubleshooting, did you print out the result of this string to make sure, e.g. after the substr(), that the path is correct for $courselocation/images/$value before placing it within the <IMG> tag?
    --newbie00
Re: displaying an image
by giulienk (Curate) on Jan 17, 2002 at 18:12 UTC
    When writing CGI scripts it's always useful to use CGI. In your case something like the following may work.
    use CGI qw(:standard); #...your other code... print img({src => "$courselocation/images/$value"});

    $|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g

Re: displaying an image
by mrbbking (Hermit) on Jan 17, 2002 at 19:53 UTC
    One more thing to check is case. If you're developing on Windows and deploying on Unix, this can be a problem. Windows is not case sensitive, but Unix is.

    Make sure your URLs match exactly, including case.

Re: displaying an image
by Tetramin (Sexton) on Jan 18, 2002 at 06:55 UTC
    On a pc you can have <img src="c:/image.gif"> and it would display in certain browsers because it doesn't matter if it's a file path or a web url. On a remote server it won't work that way. You must use a URL not the file location. If "novonyx/suitspot/docs/perlroot/" is really the Document Root then it should be "/ist001/images/newlogotr.gif".