Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get folder permission to display with php

Tags:

php

I know it is easy to see file permissions in php, but I can't find search reference for directory permissions.

Is is possible to display the folder permission and ownership with php?

If anyone can answer please also provide the example code.

like image 237
user192344 Avatar asked Jan 17 '12 02:01

user192344


People also ask

How do I give permission to a folder in PHP?

Then, do the appropriate chmod to give the group www-data the same permissions as you. For example, if the current mode is 640 (6 for you, 4 for www-data, 0 for others, translating to -rw-r-----), set it to 660 (6 for you, 6 for www-data, 0 for others, translating to -rw-rw----).

How do you display permissions for a directory?

To view the permissions for all files in a directory, use the ls command with the -la options. Add other options as desired; for help, see List the files in a directory in Unix. In the output example above, the first character in each line indicates whether the listed object is a file or a directory.


1 Answers

PHP's fileperms function also works with directories, as you can see in Example #2.

echo substr(sprintf('%o', fileperms('/path/to/directory')), -4);
// prints something like 1777

Use fileowner to get the ID of the user who owns the file/directory.

like image 85
Evan Mulawski Avatar answered Sep 20 '22 12:09

Evan Mulawski