Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 21 additions & 37 deletions reference/filesystem/functions/fileperms.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- splitted from ./it/functions/filesystem.xml, last change in rev 1.15 -->
<!-- EN-Revision: n/a Maintainer: fernando Status: working -->
<!-- CREDITS: cortesi -->
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f5c4950be0ef12e84eea5276b15a7d143885286c Maintainer: fernando Status: ready -->
<!-- Credits: cortesi -->
<refentry xml:id="function.fileperms" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>fileperms</refname>
Expand Down Expand Up @@ -43,52 +43,36 @@ echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);
<?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';
switch ($perms & 0xF000) {
case 0x1000: $info = 'p'; break; // FIFO pipe
case 0x2000: $info = 'c'; break; // character special
case 0x4000: $info = 'd'; break; // directory
case 0x6000: $info = 'b'; break; // block special
case 0x8000: $info = '-'; break; // regular
case 0xA000: $info = 'l'; break; // symbolic link (reachable when using lstat function)
case 0xC000: $info = 's'; break; // socket

// unknown
default: $info = 'u';
}

// Owner
$setuid = $perms & 0x0800;
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
$info .= (($perms & 0x0040) ? ($setuid ? 's' : 'x') : ($setuid ? 'S' : '-'));

// Group
$setgid = $perms & 0x0400;
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
$info .= (($perms & 0x0008) ? ($setgid ? 's' : 'x') : ($setgid ? 'S' : '-'));

// World
$sticky = $perms & 0x0200;
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
$info .= (($perms & 0x0001) ? ($sticky ? 't' : 'x') : ($sticky ? 'T' : '-'));

echo $info;
?>
Expand Down