Home  >  Article  >  Backend Development  >  PHP batch modification program for windows directory permissions_PHP tutorial

PHP batch modification program for windows directory permissions_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:48:151435browse

We often encounter some problems such as directory permissions being inaccessible. At this time, there may be hundreds or thousands of files or file directories. Below I wrote an example of using PHP to batch change directory permissions.

The code is as follows Copy code

//Get the file directory list, this method returns an array
function getDir($dir=”) {
$dir=empty($dir) ? getcwd() : $dir;
$dirArray[]=NULL;
If (false != ($handle = opendir ( $dir ))) {
         $i=0;
While ( false !== ($file = readdir ( $handle )) ) {
//Remove ".", ".." and files with ".xxx" suffix
If ($file != “.” && $file != “..”&&!strpos($file,”.”)) {
                    $dirArray[$i]=$file;
                   $i++;
            }
}
​​​​ //Close handle
         closedir ( $handle );
}
Return $dirArray;
}
?>




Batch directory permission settings



if(empty($_POST)){
?>


Current directory:




Website Directory


            $dirArr=getDir();
    If(is_array($dirArr)){
               foreach($dirArr as $dir){
    ?>
                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                              }
    }
    ?>

                                                                                              
           
          
        

   

 


 

    目录权限
   

     
/G user:perm 赋予指定用户访问权限。
Perm 可以是: R 读取
W 写入
C 更改(写入)
F 完全控制

/P user:perm 替换指定用户的访问权限。
Perm 可以是: N 无
R 读取
W 写入
C 更改(写入)
F 完全控制
–>
   


 



 

    来宾帐户
   

      Internet 来宾帐户:
   

 



 



}else{
    $directorys=@$_POST['directory'];
    $Perm=trim(@$_POST['Perm']);
    $User=trim(@$_POST['User']);
?>

<br>
@echo off<br>
<?php<br />$BASE_DIR=getcwd();<br />
if(is_array($directorys)){<br />
foreach($directorys as $directory ){<br />
echo <<<EOF<br />
echo Y|cacls {$BASE_DIR}{$directory} /T /E /C /G {$User}:{$Perm} <br/><br>
EOF;<br>
}<br>
}<br>
?><br>
pause<br>


}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632813.htmlTechArticleWe often encounter some problems such as directory permissions being inaccessible. At this time, there may be hundreds or thousands of File or file directory, below I wrote a method that uses php to batch change directory permissions...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn