If you only want the permissions (lowest three octal numbers) you can use a bitwise AND to mask the bits:
<?php
fileperms($file) & 511;
?>
fileperms
(PHP 4, PHP 5)
fileperms — Liefert die Zugriffsrechte einer Datei
Beschreibung
int fileperms
( string $filename
)
Gibt die Zugriffsrechte einer Datei zurück, oder FALSE wenn ein Fehler auftrat.
Diese Funktion ist nicht für remote Dateien geeignet, die zu prüfende Datei muss über das Dateisystem des Servers verfügbar sein.
Das Ergebnis dieses Funktionsaufrufes wird zwischengespeichert. Siehe clearstatcache() für weitere Einzelheiten.
fileperms
eelco
10-Jul-2007 11:21
10-Jul-2007 11:21
paul2712 at gmail dot com
02-Jun-2007 06:08
02-Jun-2007 06:08
Do not forget: clearstatcache();
==============================
When ever you make a:
mkdir($dstdir, 0770 ))
or a:
chmod($dstdir, 0774 );
You have to call:
clearstatcache();
before you can call:
fileperms($dstdir);
chinello at gmail dot com
25-Apr-2007 06:43
25-Apr-2007 06:43
On Linux (not tested on Windows), if you want a chmod-like permissions, you can use this function:
<?php
function file_perms($file, $octal = false)
{
if(!file_exists($file)) return false;
$perms = fileperms($file);
$cut = $octal ? 2 : 3;
return substr(decoct($perms), $cut);
}
?>
Using it:
$ touch foo.bar
$ chmod 0754 foo.bar
<?php
echo file_perms('foo.bar'); // prints: 754
echo file_perms('foo.bar', true); // prints 0754
?>
