开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜