Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Check if image file exists

by htmanning (Scribe)
on Apr 08, 2012 at 01:23 UTC ( #963957=note: print w/ replies, xml ) Need Help??


in reply to Re: Check if image file exists
in thread Check if image file exists

I think I spoke too soon, or I'm doing something wrong. The following doesn't work. It returns all noavatar50.png.

$picture="/$username/$picture"; if ($picture && -f $picture ) { $thumb30 = "<img src=\"$picture\" width=30 height=30 border=0> +"; } else { $thumb30 = "<img src=\"/images/noavatar50.png\" width=30 h +eight=30 border=0>"; }
Ideally I'd like to use something like this for the first IF statement, but it doesn't work.
if (($picture) && ($scope ne "Private") && (-f $picture)) {


Comment on Re^2: Check if image file exists
Select or Download Code
Re^3: Check if image file exists
by aaron_baugher (Curate) on Apr 08, 2012 at 03:50 UTC

    Perl's file-test operators only care about the file's location on your server. If the file's URI is /username/picture.jpg, that's almost certainly not the file's full pathname on your system. That might be something like /var/www/images/username/picture.jpg, or something entirely different. You'll have to prepend $picture with the filesystem location of your picture subdirectory. Also, use a different quoting method to get rid of those backslashed quotes:

    $picture = "/$username/$picture"; my $picture_path = "/var/www/images$picture"; # or whatever if( -f $picture_path ){ $thumb30 = qq| <img src="$picture" /> |; } else { $thumb30 = qq| <img src="/images/noavatar50.png" /> |; }

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963957]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2015-07-03 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (55 votes), past polls