reference/filesystem/functions/fileperms.xml
871a231f4a1caa5fb258ae53b1bb7d1fb2a0f949
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.fileperms">
3
+
<refentry xml:id="function.fileperms" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>fileperms</refname>
6
6
<refpurpose>Gets file permissions</refpurpose>
...
...
@@ -9,7 +9,7 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>int</type><methodname>fileperms</methodname>
12
+
<type class="union"><type>int</type><type>false</type></type><methodname>fileperms</methodname>
13
13
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
14
14
</methodsynopsis>
15
15
<para>
...
...
@@ -41,7 +41,7 @@
41
41
however on most platforms the return value will also include information on
42
42
the type of file given as <parameter>filename</parameter>. The examples
43
43
below demonstrate how to test the return value for specific permissions and
44
-
file types on POSIX systems, including Linux and Mac OS X.
44
+
file types on POSIX systems, including Linux and macOS.
45
45
</para>
46
46
<para>
47
47
For local files, the specific return value is that of the
...
...
@@ -51,6 +51,14 @@
51
51
documentation is recommended if parsing the non-permission bits of the
52
52
return value is required.
53
53
</para>
54
+
<para>
55
+
Returns &false; on failure.
56
+
</para>
57
+
</refsect1>
58
+

59
+
<refsect1 role="errors">
60
+
&reftitle.errors;
61
+
&fs.emits.warning.on.failure;
54
62
</refsect1>
55
63

56
64
<refsect1 role="examples">
...
...
@@ -81,30 +89,30 @@ echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);
81
89
<?php
82
90
$perms = fileperms('/etc/passwd');
83
91

84
-
if (($perms & 0xC000) == 0xC000) {
85
-
// Socket
86
-
$info = 's';
87
-
} elseif (($perms & 0xA000) == 0xA000) {
88
-
// Symbolic Link
89
-
$info = 'l';
90
-
} elseif (($perms & 0x8000) == 0x8000) {
91
-
// Regular
92
-
$info = '-';
93
-
} elseif (($perms & 0x6000) == 0x6000) {
94
-
// Block special
95
-
$info = 'b';
96
-
} elseif (($perms & 0x4000) == 0x4000) {
97
-
// Directory
98
-
$info = 'd';
99
-
} elseif (($perms & 0x2000) == 0x2000) {
100
-
// Character special
101
-
$info = 'c';
102
-
} elseif (($perms & 0x1000) == 0x1000) {
103
-
// FIFO pipe
104
-
$info = 'p';
105
-
} else {
106
-
// Unknown
107
-
$info = 'u';
92
+
switch ($perms & 0xF000) {
93
+
case 0xC000: // socket
94
+
$info = 's';
95
+
break;
96
+
case 0xA000: // symbolic link
97
+
$info = 'l';
98
+
break;
99
+
case 0x8000: // regular
100
+
$info = 'r';
101
+
break;
102
+
case 0x6000: // block special
103
+
$info = 'b';
104
+
break;
105
+
case 0x4000: // directory
106
+
$info = 'd';
107
+
break;
108
+
case 0x2000: // character special
109
+
$info = 'c';
110
+
break;
111
+
case 0x1000: // FIFO pipe
112
+
$info = 'p';
113
+
break;
114
+
default: // unknown
115
+
$info = 'u';
108
116
}
109
117

110
118
// Owner
...
...
@@ -142,11 +150,6 @@ echo $info;
142
150
</para>
143
151
</refsect1>
144
152

145
-
<refsect1 role="errors">
146
-
&reftitle.errors;
147
-
&fs.emits.warning.on.failure;
148
-
</refsect1>
149
-

150
153
<refsect1 role="notes">
151
154
&reftitle.notes;
152
155
&note.clearstatcache;
...
...
@@ -165,7 +168,6 @@ echo $info;
165
168
</refsect1>
166
169

167
170
</refentry>
168
-

169
171
<!-- Keep this comment at the end of the file
170
172
Local variables:
171
173
mode: sgml
172
174