【问题标题】:file_exists in php codefile_exists 在 php 代码中
【发布时间】:2011-10-02 20:30:15
【问题描述】:

我有一个简单的声明如下:

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

该文件在那里,但它总是转到默认图像。我做错了什么?

【问题讨论】:

  • 你确定你的路径是正确的吗?试试./images/alum/...
  • 我建议阅读一些关于相对路径和绝对路径的信息 - 文件路径(文件系统上的文件路径)和 URL 路径(与 <a href=''></a> 和其他 HTML 标记一起使用的地址)。阅读后,您应该了解并能够判断何时(以及为什么)使用./images/images//images/

标签: php file-exists


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    改成这个。

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

    【讨论】:

      【解决方案3】:

      试试:

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

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 2010-10-22
          • 2016-04-29
          • 2016-01-23
          • 2011-10-04
          • 2018-12-20
          • 2011-01-03
          • 2013-08-21
          • 2012-09-02
          • 2012-07-08
          相关资源
          最近更新 更多