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?
PHP | is_writable() Function The is_writable() function in PHP used to check whether the specified file is writable or not. The name of the file is sent as a parameter to the is_writable() function and it returns True if the filename exists and is writable.
Checking file permissionsis_readable() function returns true if the file exists and is readable; otherwise, it returns false . is_writable() function returns true if the file exists and is writable; otherwise, it returns false .
Set php files to 640. For maximum security you should set minimum permissions, which is 640. The owner 6 would be the one uploading the files.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With