技术笔记
当前位置:首页 > 商学院 > 技术笔记 > 正文内容

技术笔记

php获取文件权限

豫唐网络2023-03-07 08:031271

获取文件的权限,权限格式分为数值格式(如0644)和字符表达格式(如-rw-r--r--)两种

数值格式应用案例

$url="1.txt";
$name=GetFilePermsOct($url);
print_r($name);

输出结果为:

0644

数值格式函数

functionGetFilePermsOct($f)
{
if(!file_exists($f)){
return'';
}

returnsubstr(sprintf('%o',fileperms($f)),-4);
}

字符表达格式应用案例

$url="1.txt";
$name=GetFilePerms($url);
print_r($name);

输出结果为:

-rw-r--r--

字符表达格式函数

functionGetFilePerms($f)
{
if(!file_exists($f)){
return'';
}

$perms=fileperms($f);
switch($perms&0xF000){
case0xC000://socket
$info='s';
break;
case0xA000://symboliclink
$info='l';
break;
case0x8000://regular
$info='-';
break;
case0x6000://blockspecial
$info='b';
break;
case0x4000://directory
$info='d';
break;
case0x2000://characterspecial
$info='c';
break;
case0x1000://FIFOpipe
$info='p';
break;
default://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':'-'));

//Other
$info.=(($perms&0x0004)?'r':'-');
$info.=(($perms&0x0002)?'w':'-');
$info.=(($perms&0x0001)?(($perms&0x0200)?'t':'x'):(($perms&0x0200)?'T':'-'));

return$info;
}

扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/566.html

分享给朋友:

相关文章

vscode运行php和Composer

vscode运行php和Composer

需要用到的工具1、安装php(官网下载)2、安装composer(官网)3、vscode插件PHP Server4、vscode插件PHP Debug5、windows 11系统步骤1、安装php安装...

php删除连续空格

php删除连续空格

对字段中的连续空格进行删除只保留一个。应用案例$txt="abcytecn1"; $name=RemoveMoreSpaces($sss); echo$name;输出结果为:a...

php获取当前目录下文件夹列表

php获取当前目录下文件夹列表

获取当前目录下文件夹的名称应用案例$url="D:/wwwroot/ytecn.com/ui/"; $list=GetDirsInDir($url); print_r($lis...

PHP获取文件后缀名

PHP获取文件后缀名

获取文件后缀名,识别当前文件是什么类型的。应用案例$url="1.txt"; $name=GetFileExt($url); print_r($name);输出结果为:txt函...

php在字符串型的参数表中新加参数删除参数查询参数

php在字符串型的参数表中新加参数删除参数查询参数

字符串型的参数表加入一个新参数,从字符串型的参数表中删除一个参数,在字符串参数值查找参数。加入新参数应用案例$array="1|2|3|4"; $name=AddNameInSt...