程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php批量設置IIS目錄實例代碼

php批量設置IIS目錄實例代碼

編輯:關於PHP編程

本文章給各位同學介紹一個php批量設置IIS目錄實例代碼,希望此教程 對大家會有所幫助呀。  代碼如下 復制代碼 <?php
//獲取文件目錄列表,該方法返回數組
function getDir($dir='') {
    $dir=empty($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" />
<title>IIS目錄批量設置</title>
<style>
body {
    font:12px/22px "Microsoft YaHei", SimSun;
}
input, select, texteare, button {
    font-family:"Microsoft YaHei", SimSun;
}
</style>
</head>
<body>
<?php
if(empty($_POST)){
?>
<form action="" method="post"  onsubmit="return check();">
<h2>當前目錄:<?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="Execute" onchange="Warning(this.value)">
        <option value="0" selected="selected">無</option>
        <option value="1">純腳本</option>
        <option value="2">腳本和可執行</option>
      </select>
    </div>
  </fieldset>
</div>
<div>
  <fieldset>
    <legend>站點信息</legend>
    <div>
      站點ID: <input name="SiteId" id="SiteId" 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 SiteId = document.getElementById("SiteId"); //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 Warning(value) {
        if(value==2){
        alert('目錄擁有 "腳本和可執行" 權限會很危險請慎重選擇!')
        }
    }
    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('請先選擇目錄!');
            return false;
        }
        if(SiteId.value==""){
            alert('請輸入站點ID!');
            return false;
        }
        return true;
    }
</script>
<?php
}else{
    $directorys=@$_POST['directory'];
    $Execute=@$_POST['Execute'];
    $SiteId=@$_POST['SiteId'];
    $SiteId=trim($SiteId);
    if($Execute=0){
        $ExecutePermission="AccessRead";
    }
    if($Execute=1){
        $ExecutePermission="AccessRead | AccessScript";
    }
    if($Execute=1){
        $ExecutePermission="AccessExecute | AccessRead | AccessScript";
    }
?>
<div>
<pre>
<?php
if(is_array($directorys)){
    foreach($directorys as $directory ){
        echo <<<EOF
&lt;IIsWebDirectory Location ="/LM/W3SVC/{$SiteId}/root/{$directory}"
    AccessFlags="{$ExecutePermission}"
&gt;
&lt;/IIsWebDirectory&gt;rn
EOF;
    }
}
?>
</pre>
</div>
<?php
}
?>
</body>
</html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved