PHP | fileperms( ) Function

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:



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:

  1. clearstatcache() function needs to be called everytime before calling fileperms() function if mkdir() or chmod() functions have been used prior to fileperms() function.
  2. The buffer must be cleared if the fileperms() function is used multiple times.
  3. The fileperms() function emits an E_WARNING in case of a failure.

Examples:

Input : fileperms("gfg.txt");
Output : 33206

Input : substr(sprintf("%o", fileperms("gfg.txt")), -4);
Output : 0644

Below programs illustrate the fileperms() function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// file permissions are displayed
// using fileperms() function
echo fileperms("gfg.txt");
  
?>

chevron_right


Output:

33206

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// file permissions are displayed in
// octal format using fileperms() function
echo substr(sprintf("%o", fileperms("gfg.txt")), -4);
  
?>

chevron_right


Output:

0644

Reference:
http://php.net/manual/en/function.fileperms.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.