Table of Contents
当前目录:
Home php教程 php手册 php批量修改windows目录权限程序

php批量修改windows目录权限程序

May 25, 2016 pm 04:44 PM

我们经常会碰到一些问题像目录权限无法访问了,这时可能有几百或上千个文件或文件目录,下面我写了一个利用php来批量更改目录权限的实例,代码如下:

<?php 
	//获取文件目录列表,该方法返回数组 
	function getDir($dir=") { 
	    $dir=emptyempty($dir) ? getcwd() : $dir; 
	    $dirArray[]=NULL; 
	    if (false != ($handle = opendir ( $dir ))) { 
	        $i=0; 
	        while ( false !== ($file = readdir ( $handle )) ) { 
	            //去掉""."、".."以及带".xxx"后缀的文件 
	            if ($file != "." && $file != ".."&&!strpos($file,".")) { 
	                $dirArray[$i]=$file; 
	                $i++; 
	            } 
	        } 
	        //关闭句柄 
	        closedir ( $handle ); 
	    } 
	    return $dirArray; 
	} 
	 
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
	<html xmlns="http://www.w3.org/1999/xhtml"> 
	<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8&Prime; /> 
	<title>目录权限批量设置</title> 
	<style> 
	body { 
	    font:12px/22px "Microsoft YaHei", SimSun; 
	} 
	input, select, texteare, button { 
	    font-family:"Microsoft YaHei", SimSun; 
	} 
	</style> 
	</head> 
	<body> 
	<?php  
	if(emptyempty($_POST)){ 
	 
	<form action="" method="post"  onsubmit="return check();"> 
	<h2 id="当前目录-php-nbsp-echo-nbsp-getcwd">当前目录:<?php echo getcwd();</h2> 
	<div> 
	  <fieldset> 
	    <legend>网站目录</legend> 
	    <div> 
	      <ul> 
	<?php  
	      $dirArr=getDir(); 
	      if(is_array($dirArr)){ 
	          foreach($dirArr as $dir){ 
	 
	        <li> 
	          <label> 
	            <input name="directory[]" type="checkbox" value="<?php echo $dir;" /> 
	           <?php echo $dir;</label> 
	        </li> 
	<?php       
	          } 
	      } 
	 
	      </ul> 
	        <div> 
	        <input id="CheckALL" type="button" onclick="checkAll();" value="全选" /> 
	        <input id="NoCheckAll" type="button" onclick="noCheckAll();" value="全不选" /> 
	        <input id="inverse" type="button" onclick="inverseCheck()" value="反选" /> 
	         </div> 
	    </div> 
	  </fieldset> 
	</div> 
	<div> 
	  <fieldset> 
	    <legend>目录权限</legend> 
	    <div> 
	      <select name="Perm"> 
	        <option value="N" selected="selected">N-无</option> 
	        <option value="R">R-读取</option> 
	        <option value="W">W-写入</option> 
	        <option value="C">C-更改(写入)</option> 
	        <option value="F">F-完全控制</option> 
	      </select> 
	<!&ndash; 
	/G user:perm  赋予指定用户访问权限。 
	              Perm 可以是: R  读取 
	                          W  写入 
	                          C  更改(写入) 
	                          F  完全控制 
	 
	/P user:perm  替换指定用户的访问权限。 
	              Perm 可以是: N  无 
	                          R  读取 
	                          W  写入 
	                          C  更改(写入) 
	                          F  完全控制 
	&ndash;> 
	    </div> 
	  </fieldset> 
	</div> 
	<div> 
	  <fieldset> 
	    <legend>来宾帐户</legend> 
	    <div> 
	      Internet 来宾帐户: <input name="User" id="User" type="text" value="" /> 
	    </div> 
	  </fieldset> 
	</div> 
	<div style="margin-top:20px; padding-left:20px;"> 
	  <input type="submit" value="提交" /> 
	</div> 
	</form> 
	<script type="text/javascript"> 
	    var all = document.getElementById("CheckALL"); //全选 
	    var single = document.getElementsByName("directory[]"); //选项 
	    var noAll = document.getElementById("NoCheckAll"); //不全选 
	    var inverse = document.getElementById("inverse"); //反选 
	    var User = document.getElementById("User"); //SiteId 
	    function checkTrue() { 
	        for (var i = 0; i < single.length; i++) { 
	            single[i].checked = true; 
	        } 
	    } 
	    function checkFalse() { 
	        for (var i = 0; i < single.length; i++) { 
	            single[i].checked = false; 
	        } 
	    } 
	    //全选 
	    function checkAll() { 
	        if (all.disabled == false) { 
	            noAll.disabled = false; 
	            checkTrue(); 
	        } 
	        else { 
	            noAll.disabled = true; 
	            checkFalse(); 
	        } 
	        all.disabled = true; 
	    } 
	    //全不选 
	    function noCheckAll() { 
	        if (noAll.disabled == false) { 
	            all.disabled = false; 
	            checkFalse(); 
	        } 
	        else { 
	            all.checked = true; 
	            checkTrue(); 
	        } 
	        noAll.disabled = true; 
	    } 
	    //反选 
	    function inverseCheck() { 
	        noAll.disabled = false; 
	        all.disabled = false; 
	        for (var i = 0; i < single.length; i++) { 
	            single[i].checked = !single[i].checked; 
	        } 
	    } 
	    function check(){ 
	        var checkd_sum; 
	        checkd_sum=0; 
	        for (var i = 0; i < single.length; i++) { 
	            if(single[i].checked ==true){ 
	            checkd_sum++; 
	            } 
	        } 
	        if(checkd_sum==0){ 
	            alert(&#039;请先选择目录!&#039;); 
	            return false; 
	        } 
	        if(User.value==""){ 
	            alert(&#039;请输入Internet 来宾帐户!&#039;); 
	            return false; 
	        } 
	        return true; 
	    } 
	</script> 
	<?php 
	}else{ 
	    $directorys=@$_POST[&#39;directory&#39;]; 
	    $Perm=trim(@$_POST[&#39;Perm&#39;]); 
	    $User=trim(@$_POST[&#39;User&#39;]); 
	 
	<div> 
	<pre class="brush:php;toolbar:false"> 
	@echo off 
	<?php 
	$BASE_DIR=getcwd(); 
	if(is_array($directorys)){ 
	    foreach($directorys as $directory ){ 
	        echo <<<EOF 
	echo Y|cacls {$BASE_DIR}{$directory} /T /E /C /G {$User}:{$Perm} <br/> 
	EOF; 
	    } 
	} 
	 
	pause 
	
Copy after login

本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)