fileperms()
As you can set file permissions with chmod(), you can get them with this function.
It returns a decimal integer. I’ll show you one method of converting that to what you’re used to with chmod(). There are a number of ways to do that. Here’s one using decoct() and substr(). Also, be aware that the results of this function are cached - see clearstatcache()
clearstatcache(); $perms = fileperms( 'output.txt' ); // 33206 $octal_perms = substr( decoct( $perms ), -4 ); // 0666
What that last line did was convert the decimal to octal, then it’s converted to a string when used in substr(), then we ask for only the last four characters. So you actually get a string with this method, but that is suitable for displaying and will be properly converted to octal if used in chmod() for example.
