php_exists在php代码中

时间:2011-07-11 14:23:14

标签: php file-exists

我在下面有一个简单的陈述:

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

文件在那里,但它始终是默认图像。我有什么问题?

4 个答案:

答案 0 :(得分:1)

您在服务器上说文件系统根目录下的文件存在。您可能需要添加一些...

答案 1 :(得分:0)

尝试:

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

即。将“/ images”更改为“./images”,但仅限于file_exists调用。

答案 2 :(得分:0)

将其更改为此。

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

答案 3 :(得分:0)

确保$profile['pic']具有有效的文件名,带路径的收缩有效,并且带有parth的当前目录指向文件...

从配置文件中查看文件的临时否定条件......