aidan           Wed Jul 14 06:42:30 2004 EDT

  Modified files:              
    /phpdoc/en/reference/filesystem/functions   fileperms.xml 
  Log:
  Added two examples for displaying permissions
  
http://cvs.php.net/diff.php/phpdoc/en/reference/filesystem/functions/fileperms.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/reference/filesystem/functions/fileperms.xml
diff -u phpdoc/en/reference/filesystem/functions/fileperms.xml:1.4 
phpdoc/en/reference/filesystem/functions/fileperms.xml:1.5
--- phpdoc/en/reference/filesystem/functions/fileperms.xml:1.4  Sat Nov 29 11:39:55 
2003
+++ phpdoc/en/reference/filesystem/functions/fileperms.xml      Wed Jul 14 06:42:29 
2004
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
 <!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
   <refentry id="function.fileperms">
    <refnamediv>
@@ -15,17 +15,113 @@
     <para>    
      Returns the permissions on the file, or &false; in case of an error.
     </para>
-    
     &note.clearstatcache;
-    
     &tip.fopen-wrapper.stat;
-    
+    <example>
+        <title>Display as an octal value</title>
+        <programlisting role="php">
+<![CDATA[
+<?php
+// Returns 1777
+echo substr(sprintf('%o', fileperms('/tmp')), -4);
+
+// Returns 0644
+echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);
+?>
+]]>
+        </programlisting>
+    </example>
+    <example>
+        <title>Display permissions</title>
+        <programlisting role="php">
+<![CDATA[
+<?php
+$perms = fileperms('/etc/passwd');
+
+if (($perms & 0xC000) == 0xC000) {
+    // Socket
+    $info = 's';
+} elseif (($perms & 0xA000) == 0xA000) {
+    // Symbolic Link
+    $info = 'l';
+} elseif (($perms & 0x8000) == 0x8000) {
+    // Regular
+    $info = '-';
+} elseif (($perms & 0x6000) == 0x6000) {
+    // Block special
+    $info = 'b';
+} elseif (($perms & 0x4000) == 0x4000) {
+    // Directory
+    $info = 'd';
+} elseif (($perms & 0x2000) == 0x2000) {
+    // Character special
+    $info = 'c';
+} elseif (($perms & 0x1000) == 0x1000) {
+    // FIFO pipe
+    $info = 'p';
+} else {
+    // Unknown
+    $info = 'u';
+}
+
+// Owner
+$info .= (($perms & 0x0100) ? 'r' : '-');
+$info .= (($perms & 0x0080) ? 'w' : '-');
+$info .= (($perms & 0x0040) ?
+            (($perms & 0x0800) ? 's' : 'x' ) :
+            (($perms & 0x0800) ? 'S' : '-'));
+
+// Group
+$info .= (($perms & 0x0020) ? 'r' : '-');
+$info .= (($perms & 0x0010) ? 'w' : '-');
+$info .= (($perms & 0x0008) ?
+            (($perms & 0x0400) ? 's' : 'x' ) :
+            (($perms & 0x0400) ? 'S' : '-'));
+
+// World
+$info .= (($perms & 0x0004) ? 'r' : '-');
+$info .= (($perms & 0x0002) ? 'w' : '-');
+$info .= (($perms & 0x0001) ?
+            (($perms & 0x0200) ? 't' : 'x' ) :
+            (($perms & 0x0200) ? 'T' : '-'));
+
+echo $info;
+?>
+]]>
+        </programlisting>
+        <screen>
+<![CDATA[
+-r--r--r--
+]]>
+        </screen>
+    </example>
     <simpara>
      See also <function>is_readable</function>,
      and <function>stat</function>
     </simpara>
    </refsect1>
   </refentry>
+
+  <!-- 
+  
+  
+  
+  <?php
+
+?> 
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  -->
 
 <!-- Keep this comment at the end of the file
 Local variables:

Reply via email to