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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.