file_exists returning false but I know the file exists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

file_exists returning false but I know the file exists

Post by Luke »

For some reason this is returning false:

Code: Select all

if (file_exists('/home/luke/sites/library/Zend/library/Zend/View.php'))
{
    // Do something
}
I know that file exists because I just opened it. I type location in as /home/luke/sites/library/Zend/library/Zend and I see View.php in the directory! What could be causing this?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

OK, it seems to be a permissions issue...

I still am not a real permissions hero. How would I give php read access to the library directory and everything under it?

forgive my n00bishness... in phpinfo() the only thing I get about users/groups is this:

User/Group www-data(33)/33

so... would I chmod the library to give read access to www-data(33)?? I really need to read up on this stuff.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP will likely fall into the "other" category. Read will obviously be needed, execute may be needed on some systems.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I'm sorry... what do you mean by this?
PHP will likely fall into the "other" category
:oops: EDIT - nvm - thanks google!

See this is just another reason I'm glad I switched over to linux. I've never had to worry about this stuff before... I need to actually sit down and REALLY read up on *nix and file permissions and I plan to, but you guys know as well as I do that it's easier said than done. I'm so damn busy right now it's hard to fit ANYTHING extra in. I think it's really important that I know this stuff though, so it's going to the top of my priority list.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

permissions are the binary representation of read/write/execute for user/group/world, so if the file is owned by the same user as is running php , then r--xxxxxx (4xx) should be fine.

It's likely not owned by the same user, nor will they be in the same group. In such a case you'll need to grand read access to the "world". (xx4)

A very common file permission in linux is rw-r--r-- (644) which gives the user read/write access, and everyone else read-only access.

You use chmod to set the permissions, and chown to reset ownership. a quick `man chmod | less` will give you a handy reference :-)
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

You could also give it sticky privileges, but I'll let you read up via Google before we go into that :p
Post Reply