Search code examples
phpyiifile-exists

file_exists returns false even when the file exists in my yii php application


enter image description here

I have read so many questions which bear the same title as mine, but none of them has helped me..

Above image is the output of the following function..

foreach (  $products as $product) {

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

          }

And Here is the function getCatalogUploadPath()...

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

and Here is the 'config'..

'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/',
            )

PROOF THAT THE FILE EXISTS :

enter image description here


Solution

  • The filename $product['image'] is malformed. It doesn't contain file extension, which is why file_exists() returns false