开发者

file_exists in php code

开发者 https://www.devze.com 2023-03-19 23:13 出处:网络
I have a simple statement below: if(file_exists(\'/images/alum/\'.$profile[\'pic\'])) echo \'/images/alum/\'.$profile[\'pic\'];

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';

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

0

精彩评论

暂无评论...
验证码 换一张
取 消