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();
fileperms
(PHP 4, PHP 5)
fileperms — Zistí práva k danému súboru
Popis
int fileperms
( string $názovsúboru
)
Vráti práva k zadanému súboru alebo FALSE v prípade chyby.
Výsledky tejto funkcie sú cacheované. Bližšie informácie môžete nájsť pri funkcii clearstatcache().
Táto funkcia nepracuje so vzdialenými súbormi; súbor, ktorý má byť preskúmaný, musí byť prístupný cez súborový systém servera.
fileperms
MartinAngermeier at gmx dot net
29-Oct-2008 01:37
29-Oct-2008 01:37
eelco
10-Jul-2007 02:21
10-Jul-2007 02: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 09:08
02-Jun-2007 09: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
24-Apr-2007 09:43
24-Apr-2007 09: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
?>
