简体   繁体   中英

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?

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 ..

Try:

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

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

Change it to this.

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

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM