summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2008-05-08 17:00:28 +0200
committerDerek Jones <derek.jones@ellislab.com>2008-05-08 17:00:28 +0200
commit94a2182c95cc95646ad582616d335bce62152c86 (patch)
tree8a803da29c737996d4708e64599f6ea9b1214048 /system
parentee0a7f0083e9e3e2e667211acd3909e71aa1ec47 (diff)
added symbolic_permissions() and octal_permissions() to the File helper
Diffstat (limited to 'system')
-rw-r--r--system/helpers/file_helper.php88
1 files changed, 88 insertions, 0 deletions
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php
index 21ed5ff97..bdde2d55d 100644
--- a/system/helpers/file_helper.php
+++ b/system/helpers/file_helper.php
@@ -368,4 +368,92 @@ if (! function_exists('get_mime_by_extension'))
}
}
+// --------------------------------------------------------------------
+
+/**
+ * Symbolic Permissions
+ *
+ * Takes a numeric value representing a file's permissions and returns
+ * standard symbolic notation representing that value
+ *
+ * @access public
+ * @param int
+ * @return string
+ */
+if (! function_exists('symbolic_permissions'))
+{
+ function symbolic_permissions($perms)
+ {
+ if (($perms & 0xC000) == 0xC000)
+ {
+ $symbolic = 's'; // Socket
+ }
+ elseif (($perms & 0xA000) == 0xA000)
+ {
+ $symbolic = 'l'; // Symbolic Link
+ }
+ elseif (($perms & 0x8000) == 0x8000)
+ {
+ $symbolic = '-'; // Regular
+ }
+ elseif (($perms & 0x6000) == 0x6000)
+ {
+ $symbolic = 'b'; // Block special
+ }
+ elseif (($perms & 0x4000) == 0x4000)
+ {
+ $symbolic = 'd'; // Directory
+ }
+ elseif (($perms & 0x2000) == 0x2000)
+ {
+ $symbolic = 'c'; // Character special
+ }
+ elseif (($perms & 0x1000) == 0x1000)
+ {
+ $symbolic = 'p'; // FIFO pipe
+ }
+ else
+ {
+ $symbolic = 'u'; // Unknown
+ }
+
+ // Owner
+ $symbolic .= (($perms & 0x0100) ? 'r' : '-');
+ $symbolic .= (($perms & 0x0080) ? 'w' : '-');
+ $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
+
+ // Group
+ $symbolic .= (($perms & 0x0020) ? 'r' : '-');
+ $symbolic .= (($perms & 0x0010) ? 'w' : '-');
+ $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
+
+ // World
+ $symbolic .= (($perms & 0x0004) ? 'r' : '-');
+ $symbolic .= (($perms & 0x0002) ? 'w' : '-');
+ $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
+
+ return $symbolic;
+ }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Octal Permissions
+ *
+ * Takes a numeric value representing a file's permissions and returns
+ * a three character string representing the file's octal permissions
+ *
+ * @access public
+ * @param int
+ * @return string
+ */
+if (! function_exists('octal_permissions'))
+{
+ function octal_permissions($perms)
+ {
+ return substr(sprintf('%o', $perms), -3);
+ }
+}
+
?> \ No newline at end of file