【问题标题】:Why file_exists() function doesn't work correctly?为什么 file_exists() 函数不能正常工作?
【发布时间】:2017-03-27 17:29:25
【问题描述】:

这是我的代码:

<?php $filename = $var.'p_folder/'.sub_replace('?','',$page).'/images/default.png'; ?>
<img src  = "<?php echo $filename; ?>"
     title= "<?php echo file_exists($filename) ? 'exists' : 'not exist'; ?>" 
>

我的代码也显示了图像,但 file_exists() 返回 false (我的意思是“不存在”打印).. 为什么?

其实这对我来说很奇怪..因为我可以在网络上看到图像,所以这意味着图像存在于目录中,但是为什么file_exists() 找不到呢?

【问题讨论】:

  • 您是否尝试过不嵌入它,而是首先设置 $filename 并将该变量嵌入到 元素上?
  • 你应该试试 " title="" >
  • file_exists检查文件路径而不是文件url

标签: php html function path directory


【解决方案1】:

检查您的图像路径,然后服务器名称和文档根目录

【讨论】:

    【解决方案2】:

    file_exists() 需要使用硬盘驱动器上的文件路径,而不是 URL。所以你应该有更多类似的东西:

    $thumb_name = $_SERVER['DOCUMENT_ROOT'] . 'images/abcd.jpg';
    
    if(file_exists($thumb_name)) {
       //your code
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多