php 修改文件的权限_PHP: chmod - Manual

error_reporting(E_ERROR|E_PARSE);/* Makes is so Directories are not browseable to the public,

removing only the Public = Read permission, while leaving

the other chmod permissions for the file in tact.

If you have exectue already on, and read off, public viewers will only

be able to view files through links, but not browse

around to see what's inside of directories and see what

you've got laying around. */

//-------------------------------------------------------

// Get file mode

// Get file permissions supported by chmodfunctiongetmod($filename) {$val=0;$perms=fileperms($filename);// Owner; User$val+= (($perms&0x0100) ?0x0100:0x0000);//Read$val+= (($perms&0x0080) ?0x0080:0x0000);//Write$val+= (($perms&0x0040) ?0x0040:0x0000);//Execute

// Group$val+= (($perms&0x0020) ?0x0020:0x0000);//Read$val+= (($perms&0x0010) ?0x0010:0x0000);//Write$val+= (($perms&0x0008) ?0x0008:0x0000);//Execute

// Global; World$val+= (($perms&0x0004) ?0x0004:0x0000);//Read$val+= (($perms&0x0002) ?0x0002:0x0000);//Write$val+= (($perms&0x0001) ?0x0001:0x0000);//Execute

// Misc$val+= (($perms&0x40000) ?0x40000:0x0000);//temporary file (01000000)$val+= (($perms&0x80000) ?0x80000:0x0000);//compressed file (02000000)$val+= (($perms&0x100000) ?0x100000:0x0000);//sparse file (04000000)$val+= (($perms&0x0800) ?0x0800:0x0000);//Hidden file (setuid bit) (04000)$val+= (($perms&0x0400) ?0x0400:0x0000);//System file (setgid bit) (02000)$val+= (($perms&0x0200) ?0x0200:0x0000);//Archive bit (sticky bit) (01000)return$val;

}//-------------------------------------------------------

// Find out if file has modefunctionhasmod($perms,$permission) {# User Read = 0400 (256), Write = 0200 (128), Execute = 0100 (64)

# Group Read = 0040 (32), Write = 0020 (16), Execute = 0010 (8)

# Public Read = 0004 (4), Write = 0002 (2), Execute = 0001 (1)return (($perms&$permission) ==$permission);

}//-------------------------------------------------------

// Take the read option off of all the subdirectories of the included pathfunctionpathlock($dir,$listall=false,$testrun=true) {

echo"START @ ".date("F j, Y, h:i:s A") ."
";

echo ($testrun?'**Test Run Activated (no changes will be made).**
':'**Live Run Activated.**
');

echo$dir." is our directory.
\n";

echo"[...IN PROGRESS...]
";$file_list='';$stack[] =$dir;

while ($stack) {$current_dir=array_pop($stack);

if ($dh=opendir($current_dir)) {

while (($file=readdir($dh)) !==false) {

if ($file!=='.'AND$file!=='..') {$current_file="{$current_dir}/{$file}";

if (is_dir($current_file)) {// BEG ADD PATH$mode=getmod($current_file);//Get the mode$HasPubRead=hasmod($mode,4);

if ($HasPubRead||$listall) {// Can the public read this dir?

//======================================$ch=true;$take=0;// Change the mode:if ($HasPubRead) {$take=4;// Value for Public Read. 4 is the same in octal and decimal.if (!$testrun) {$ch=chmod($current_file,$mode-$take);

}

}

echo$current_file.",current=".decoct($mode) .

(($mode!==$mode-$take) ?",new=".decoct($mode-$take) :'') .

($ch?'':',FAILED') ."
\n";

}// end if hasmod

// END ADD PATH$stack[] =$current_file;

}// if if_dir}//if ($file !== '.' AND $file !== '..')}//while (($file = readdir($dh)) !== false)}//if ($dh = opendir($current_dir))}// while ($stack)echo"
COMPLETE @ ".date("F j, Y, h:i:s A") ."
\n";

return;//return $path_list;}// end function

//-------------------------------------------------------

//listall Show all folders, even one's we're not going to process?

//testrun Do a test run without making any changespathlock($_SERVER["DOCUMENT_ROOT"],false,true);// listall?=false, testrun?=true?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值