Since the output of decoct( fileperms('.') ) is of the form: 40644
It seems the previous example is wrong, instead you should understand:
To get permissions formatted as "644":
<?php
echo substr(decoct( fileperms('.') ), 2);
?>
To get permissions formatted as "0644":
<?php
echo substr(decoct( fileperms('.') ), 1);
?>
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
jchris dot fillionr at kitware dot com
02-Apr-2009 10:11
02-Apr-2009 10:11
MartinAngermeier at gmx dot net
29-Oct-2008 08:37
29-Oct-2008 08:37
An easy way to calculate fileperms to chmod is this:
substr(decoct(fileperms("test.html")),3);
Displays 666 or 777 (depends on chmod set).
substr(decoct(fileperms("test.html")),2);
Displays 0666 or 0777 and refers immediately to the number set with chmod();
eelco
10-Jul-2007 09:21
10-Jul-2007 09:21
If you only want the permissions (lowest three octal numbers) you can use a bitwise AND to mask the bits:
<?php
fileperms($file) & 511;
?>
paul2712 at gmail dot com
02-Jun-2007 04:08
02-Jun-2007 04: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 04:43
25-Apr-2007 04: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
?>
