Yii Framework Forum: problem with file_exists() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

problem with file_exists() Rate Topic: -----

#1 User is offline   abajja 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 108
  • Joined: 05-March 09
  • Location:Barcelona, Spain

Posted 09 March 2009 - 10:16 AM

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
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,871
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 March 2009 - 10:27 AM

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

#3 User is offline   abajja 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 108
  • Joined: 05-March 09
  • Location:Barcelona, Spain

Posted 09 March 2009 - 10:57 AM

Fixed. Thank you.
0

#4 User is offline   coma 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 19-July 10

Posted 13 January 2011 - 03:23 AM

View Postqiang, on 09 March 2009 - 10:27 AM, said:

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


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.
0

#5 User is offline   GDzyne 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-June 09

Posted 13 January 2011 - 04:43 AM

View Postcoma, on 13 January 2011 - 03:23 AM, said:

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')) { ... }

0

#6 User is offline   coma 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 19-July 10

Posted 13 January 2011 - 05:09 AM

View PostGDzyne, on 13 January 2011 - 04:43 AM, said:

Try this :

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




Thanks! Works just fine! :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users