Take the 2-minute tour ×

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?

share|improve this question
Really, you only need is_writeable(), and maybe is_directory(). It's either writeable, or it isn't, so there's no need to check the individual o/g/a flags. –  Marc B Sep 5 '12 at 15:40

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
So PHP's is_writable is a shortcut to see if a directory has the correct permissions for a file to be created in it. –  David Thompson Sep 5 '12 at 16:13
Yes, that is correct –  MMCACHRAN Sep 5 '12 at 16:13

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
share|improve this answer

Your Answer


