TH1981
TH1981

Reputation: 3193

file_exists in php code

I have a simple statement below:

if(file_exists('/images/alum/'.$profile['pic'])) 
  echo '/images/alum/'.$profile['pic']; 
  else echo '/images/user_default.jpg';

The file is there but it's always going to the default image. What have I got wrong?

Upvotes: 2

Views: 1050

Answers (4)

bensiu
bensiu

Reputation: 25564

make sure that $profile['pic'] has valid file name, contraction with path is valid, and current directory with parth point to file...

temporary negate condition to see file from profile...

Upvotes: 0

Steve Nguyen
Steve Nguyen

Reputation: 5974

Change it to this.

if(file_exists('./images/alum/'.$profile['pic'])) 
    echo './images/alum/'.$profile['pic']; 
else 
    echo './images/user_default.jpg';

Upvotes: 0

ADW
ADW

Reputation: 4080

Try:

if(file_exists('./images/alum/'.$profile['pic']))
 echo '/images/alum/'.$profile['pic']; 
 else echo '/images/user_default.jpg';

i.e. changing the "/images" to "./images" but only in the file_exists call.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190935

You are saying on the server that the file at the root of the file system exists. You will have to probably add some . or ..

Upvotes: 1

Related Questions