PHP | fileperms( ) Function
Last Updated :
05 May, 2018
Improve
The fileperms() function in PHP is an inbuilt function which is used to return the permissions given to a file or a directory. The filename of the file whose permissions have to be checked is sent as a parameter to the function and it returns the permissions given to the file in the form of numbers on success and False on failure.
The result of the fileperms() function is cached and a function called clearstatcache() is used to clear the cache.
Syntax:
php
Output:
php
Output:
fileperms($filename)Parameters: The fileperms() function in PHP accepts one parameter $filename. It specifies the filename of the file whose permissions you want to check. Return Value: It returns the permissions given to the file in the form of numbers on success and False on failure. Errors And Exception:
- clearstatcache() function needs to be called everytime before calling fileperms() function if mkdir() or chmod() functions have been used prior to fileperms() function.
- The buffer must be cleared if the fileperms() function is used multiple times.
- The fileperms() function emits an E_WARNING in case of a failure.
Input : fileperms("gfg.txt"); Output : 33206 Input : substr(sprintf("%o", fileperms("gfg.txt")), -4); Output : 0644Below programs illustrate the fileperms() function. Program 1:
<?php
// file permissions are displayed
// using fileperms() function
echo fileperms("gfg.txt");
?>
33206Program 2:
<?php
// file permissions are displayed in
// octal format using fileperms() function
echo substr(sprintf("%o", fileperms("gfg.txt")), -4);
?>
0644Reference: http://php.net/manual/en/function.fileperms.php