Reputation: 115
I have a PHP script that needs to check the permissions on a directory to make sure it is writable. What I have so far is:
$perms = substr(sprintf('%o', fileperms($folder)), -4);
if ($perms == "0777" || is_writable('temp'.DS))
{
//code here
}
Is this a sufficient check?
Upvotes: 5
Views: 8874
Reputation: 484
PHP's is_writable()
should be sufficient. Below is the description from the PHP manual:
The filename argument may be a directory name allowing you to check if a directory is writable.
See http://php.net/manual/en/function.is-writable.php for more details.
Upvotes: 6
Reputation: 5179
There's no need to check the permissions manually, it's enough to use use is_writable
and is_dir
:
if (is_dir($myDir) && is_writable($myDir)){
//do stuff
}
Upvotes: 8