*fileperms* -- Gets file permissions

  int fileperms(string filename)~

Gets permissions for the given file.

{filename} Path to the file.

Returns the permissions on the file, or FALSE on failure.

Display permissions as an octal value

<?php >
  echo substr(sprintf('%o', fileperms('/tmp')), -4);
  echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);
?>

The above example will output:

  1777
  0644

Display full permissions

<?php >
  $perms = fileperms('/etc/passwd');
  
  if (($perms &amp; 0xC000) == 0xC000) {
      // Socket
      $info = 's';
  } elseif (($perms &amp; 0xA000) == 0xA000) {
      // Symbolic Link
      $info = 'l';
  } elseif (($perms &amp; 0x8000) == 0x8000) {
      // Regular
      $info = '-';
  } elseif (($perms &amp; 0x6000) == 0x6000) {
      // Block special
      $info = 'b';
  } elseif (($perms &amp; 0x4000) == 0x4000) {
      // Directory
      $info = 'd';
  } elseif (($perms &amp; 0x2000) == 0x2000) {
      // Character special
      $info = 'c';
  } elseif (($perms &amp; 0x1000) == 0x1000) {
      // FIFO pipe
      $info = 'p';
  } else {
      // Unknown
      $info = 'u';
  }
  
  // Owner
  $info .= (($perms &amp; 0x0100) ? 'r' : '-');
  $info .= (($perms &amp; 0x0080) ? 'w' : '-');
  $info .= (($perms &amp; 0x0040) ?
              (($perms & 0x0800) ? 's' : 'x' ) :
              (($perms & 0x0800) ? 'S' : '-'));
  
  // Group
  $info .= (($perms &amp; 0x0020) ? 'r' : '-');
  $info .= (($perms &amp; 0x0010) ? 'w' : '-');
  $info .= (($perms &amp; 0x0008) ?
              (($perms & 0x0400) ? 's' : 'x' ) :
              (($perms & 0x0400) ? 'S' : '-'));
  
  // World
  $info .= (($perms &amp; 0x0004) ? 'r' : '-');
  $info .= (($perms &amp; 0x0002) ? 'w' : '-');
  $info .= (($perms &amp; 0x0001) ?
              (($perms & 0x0200) ? 't' : 'x' ) :
              (($perms & 0x0200) ? 'T' : '-'));
  
  echo $info;
?>

The above example will output:

  -rw-r--r--



Upon failure, an E_WARNING is emitted.

The results of this function are cached. See |clearstatcache| for more
details.

As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer
to for a listing of which wrappers support |stat| family of functionality.

|chmod| |is_readable| |stat|

vim:ft=help:
