【问题标题】:file_exists returns false even when the file exists in my yii php application即使文件存在于我的 yii php 应用程序中,file_exists 也会返回 false
【发布时间】:2017-10-03 02:23:31
【问题描述】:

我已经阅读了很多与我同名的问题,但没有一个对我有帮助..

上图是下面函数的输出..

foreach (  $products as $product) {

            $file = Library::getCatalogUploadPath().$product['image'];
            echo $file.'<br>';
            if( file_exists($file)){
                echo  $file;
            }
            else {
                echo "no".'<br>';
            }

          }

这里是函数getCatalogUploadPath()...

public function getCatalogUploadPath()
    {
        return Yii::app()->params['config']['document_root'].Yii::app()->params['config']['upload_path'].'catalog/';
    }

这是“配置”..

'config' => array(
            'site_url' => 
            'http://l/git/cart.git/',//example:http://www.cartnex.org/
            'document_root' => $_SERVER['DOCUMENT_ROOT'],
            'upload_path'=>'git/cart.git/uploads/',
            )

文件存在的证明:

【问题讨论】:

  • 文件扩展名在哪里?
  • 是的,右键单击那只小狗(哈哈)并在属性中查看全名。
  • @DanMiller,你指引我朝着正确的方向前进.. :)
  • @DanMiller 请立即回答问题。

标签: php yii file-exists


【解决方案1】:

文件名$product['image'] 格式错误。它不包含文件扩展名,这就是为什么file_exists() 返回false

【讨论】:

    猜你喜欢
    • 2012-03-01
    • 2012-05-13
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 2012-01-31
    • 2015-02-01
    相关资源
    最近更新 更多