Jump to content

php file permissions?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
Hey, so I have googled the crap out of it, and I have found some information, but nothing helpful.

I need to see if a file is writeable with PHP code. I usually use
$var = fopen("this.txt", 'w');
if(!$var){ die("this isnt writeable"); }
But, that doesnt work in CLI, this PHP script is CLI, so what it does is opens it, then throws the error, which is weird.

I looked, the only thing close is the is_writeable, but that only checks if the file/folder belongs to the current user.

so any ideas? Thanks

Edited by Jaan, 09 December 2008 - 09:49 PM.
Please use code tags when you're posting your codes!

Checkout my new forum! http://adminreference.com/

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Do you fully understand Linux file permissions?

In many cases when you browse a php script through the browser, it is being executed by apache, as the user nobody. When you run php through the command line, it is being ran as you. So nobody may have writable permissions, while you may not. I find it really hard to believe is_writable does not determine if the file is writable (by the user executing the script). Especially since the php manual explicitly states:

Quote

Returns TRUE if the filename exists and is writable.

But perhaps you might have more success with this function PHP: fileperms - Manual