problem with file_exists()

I am trying to get file_exists() in this code working as expected but without success.

        $filename = Yii::app()->request->baseUrl . '/images/thumbnails/'.$row['products_image'];


        if (file_exists($filename)) {


            echo '<img src="'.$filename.'" alt="imatge del producte...">';


        } else {


            echo "Imatge no disponible";


        }

Any help. Thanks.

a.bajja

You can't do that because it is a URL.

Fixed. Thank you.

and what would be the fix? I’m struggling here )

I’m trying to go as follows:




   if (file_exists('/img/trololo.jpg')) { ... }



The img dir is in root dir of the project.

Try this :




if (file_exists(YiiBase::getPathOfAlias('webroot').'/img/trololo.jpg')) { ... }



Thanks! Works just fine! :)