Check file permissions

Solution 1:

Use fileperms() function

clearstatcache();
echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);

Solution 2:

You can use the is_readable(), is_executable() etc.. commands.

Solution 3:

Real coders use bitwise operations, not strings ;) This is much more elegant way of handling permissions:

function checkPerms($path)
{
    clearstatcache(null, $path);
    return decoct( fileperms($path) & 0777 );
}

Solution 4:

Use fileperms() function and substring:

substr(decoct(fileperms(__DIR__)), -4); // 0777
substr(decoct(fileperms(__DIR__)), -3); // 777

For file:

substr(decoct(fileperms(__FILE__)), -4); // 0644
substr(decoct(fileperms(__FILE__)), -3); // 644

Replace __FILE__ and __DIR__ with your path or variable