views:

41

answers:

1

In php, I need to read a file that has no read access (the file permissions are -rw-r-----). Changing the file's permissions isn't possible. The file sits on a local server.

Various methods I've tried in PHP don't work (file_get_contents, fopen, and curl) and maybe that's to be expected if that last read bit isn't set. Is that because the web server is being blocked access?

If that's the case then why is it that Firefox can read the file directly (using file://) as does curl from a shell? About to write an external python script that can read the file... what am I missing here?

+3  A: 

It depends what user owns the file, and what user PHP/Apache is running as. You could check it by running whoami from PHP. If you can't change any part of the permissions/owner on the file, nor the Apache user, then, well, you're stuffed sorry.

nickf
Yup. Denying access to unauthorized users is what file permissions are about. If they were circumventable, they would be broken.
Pekka
I see, when I use the file:// protocol, I'm the user and that file is readable. When I run the php file through the server the user is Apache, and the file is unreadable.
AK