in reply to Re: CGI-SQL-HTML-Display "no image"
in thread CGI-SQL-HTML-Display "no image"

I've probably wandered a bit from the original suggestion, but I didn't have much luck with 'unless'. I'm better with 'if' and the following statments work on my local PC, giving me the file name when the file exists and DefaultPhoto when the file is not present.(-e worked, while -f did not.)

$path = "/dir_name/sub_dir_name/"; #Determine if the image file exists my $fn = $path.$Data{dr_id}.'.jpg'; if (-e $fn) { my $image = $fn; } else { $image = $path."DefaultPhoto.gif";

When I post it to my server, it doesn't seem to find the file. It returns the requested person's information, but returns the DefaultPhoto.jpg even when the image file exists. I thought perhaps the problem was in my path name somewhere, so I printed $fn and $image to the browser. I'm pulling a person that should have a photo and I get the following back:

File is: /dir_name/sub_dir_name/BOWG.jpg Image is: /dir_name/sub_dir_name/DefaultPhoto.gif
The browser displays $image (DefaultPhoto.jpg) and returns the link in the HTML below

<TR><TD><img src=/dir_name/sub_dir_name/DefaultPhoto.gif></TD></TR>

So, I'm stumped. I am missing something but I can't see it. Is there some reason I can't actually check the file's existence on the server when I coming through a CGI script? Is there another way to do this?
TIA,
WB

Replies are listed 'Best First'.
Re: Re: Re: CGI-SQL-HTML-Display "no image"
by Zaxo (Archbishop) on May 25, 2003 at 01:53 UTC

    You need to present the img tag with src as an url. That will take transforming the filesystem path to something like 'http://host.nil/' . substr $fn, length( $ENV{DOCUMENT_ROOT})

    After Compline,
    Zaxo

      I'd feel remiss if I didn't update this node with a completed answer. (Thanks to Zaxo for the confirmation about the filesystem path.) I wasn't sure of the filesystem path on the hosting server, so I used a snippet of super-searched code from The Environment variable for URL... to find the path, which I then used in my code.
      my $path = "/web_dir/web_sub_dir/"; my $filepath = "D:\\my_ip_address\\web_dir\\web_sub_dir\\"; #Calls to database, data-fetching snipped #Determine if the image file exists $photo=$Data{ID}.'.jpg'; $fn = $filepath.$photo; if (-e $fn) { $image = "$path$photo"; } else { $image = $path."DefaultPhoto.gif"; } ##Snipped HTML display, etc....
      This works the way I need it to and displays the image if it is available or the default "no photo available" image if not. Thanks, Monks, for the assistance.
      WB