Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Check if image file exists

by htmanning (Pilgrim)
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)) {

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963957]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2018-01-18 16:50 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (213 votes). Check out past polls.