Skip to content

File or folder permission

Function to get permissions of file or folder in PHP.

function getPermission($path) {
return (is_dir($path) || is_file($path)) ? substr(decoct(fileperms($path)), -4) : '0000';
}

or you can check if permissions are sufficient:

function hasPermission($path, $permission = 777) {
$current = substr(decoct(fileperms($path)), $permission > 1000 ? -4 : -3);
return ($current > $permission);
}