Display file permission code in Unix/linux

Source: Internet
Author: User
Tags file permissions
The code is as follows Copy Code

<?php
Description: Display file permissions in unix/linux format
Finishing:

$perms = fileperms ('/etc/passwd ');

if ($perms & 0xc000) = = 0xc000) {
Socket
$info = ' s ';
} elseif (($perms & 0xa000) = = 0xa000) {
Symbolic Link
$info = ' l ';
} elseif (($perms & 0x8000) = = 0x8000) {
Regular
$info = '-';
} elseif (($perms & 0x6000) = = 0x6000) {
Block Special
$info = ' B ';
} elseif (($perms & 0x4000) = = 0x4000) {
Directory
$info = ' d ';
} elseif (($perms & 0x2000) = = 0x2000) {
Character Special
$info = ' C ';
} elseif (($perms & 0x1000) = = 0x1000) {
FIFO Pipe
$info = ' P ';
} else {
Unknown
$info = ' u ';
}

Owner
$info. = ($perms & 0x0100)? ' R ': '-');
$info. = ($perms & 0x0080)? ' W ': '-');
$info. = ($perms & 0x0040)?
($perms & 0x0800)? ' s ': ' X '):
($perms & 0x0800)? ' S ': '-'));

Group
$info. = ($perms & 0x0020)? ' R ': '-');
$info. = ($perms & 0x0010)? ' W ': '-');
$info. = ($perms & 0x0008)?
($perms & 0x0400)? ' s ': ' X '):
($perms & 0x0400)? ' S ': '-'));

World
$info. = ($perms & 0x0004)? ' R ': '-');
$info. = ($perms & 0x0002)? ' W ': '-');
$info. = ($perms & 0x0001)?
($perms & 0x0200)? ' t ': ' X '):
($perms & 0x0200)? ' T ': '-');

Echo $info;
?>

Extract permission display function from User Manager for PUREFTPD
PUREFTPD is an FTP server software under *nix, and User Manager for PUREFTPD is designed to facilitate online management of FTP users. The author is: M.mastenbroek.

The code is as follows Copy Code

<?php
Description: Extracts the permission display function from the User manager for PUREFTPD
Finishing:

function Displayfilepermissions ($Mode) {
Determine Type
if ($Mode & 0x1000) {
$Type = ' P '; FIFO Pipe
else if ($Mode & 0x2000) {
$Type = ' C '; Character Special
else if ($Mode & 0x4000) {
$Type = ' d '; Directory
else if ($Mode & 0x6000) {
$Type = ' B '; Block Special
else if ($Mode & 0x8000) {
$Type = '-'; Regular
else if ($Mode & 0xa000) {
$Type = ' l '; Symbolic Link
else if ($Mode & 0xc000) {
$Type = ' s '; Socket
} else {
$Type = ' u '; UNKNOWN
}

Determine permissions
$Owner [' read '] = ($Mode & 00400)? ' R ': '-';
$Owner [' write '] = ($Mode & 00200)? ' W ': '-';
$Owner [' execute '] = ($Mode & 00100)? ' X ': '-';
$Group [' read '] = ($Mode & 00040)? ' R ': '-';
$Group [' write '] = ($Mode & 00020)? ' W ': '-';
$Group [' execute '] = ($Mode & 00010)? ' X ': '-';
$World [' read '] = ($Mode & 00004)? ' R ': '-';
$World [' write '] = ($Mode & 00002)? ' W ': '-';
$World [' execute '] = ($Mode & 00001)? ' X ': '-';

Adjust for SUID, SGID and sticky bit
if ($Mode & 0x800) $Owner [' execute '] = ($Owner [' execute '] = = ' x ')? ' s ': ' s ';
if ($Mode & 0x400) $Group [' execute '] = ($Group [' execute '] = = ' x ')? ' s ': ' s ';
if ($Mode & 0x200) $World [' execute '] = ($World [' execute '] = = ' x ')? ' t ': ' t ';

Return
$Type
. $Owner [' Read ']. $Owner [' Write ']. $Owner [' Execute ']
. $Group [' Read ']. $Group [' Write ']. $Group [' Execute ']
. $World [' Read ']. $World [' Write ']. $World [' Execute '];
}

$perms = fileperms ('/etc/passwd ');

echo displayfilepermissions ($perms);

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.