2010-05-09 52 views
2

我想創建一個簡單的安裝腳本。以下是簡單的代碼。文件夾權限和提交按鈕

<ul> 
<?php 
function check_perms($path,$perm) 
{ 
    clearstatcache(); 
    $configmod = substr(sprintf('%o', fileperms($path)), -4); 
    $css = (($configmod != $perm) ? " class='error'" : " class='none'"); 
    echo "<li".$css.">\n"; 
    echo '<span style="float:left; padding-right:20px;">'.$path.'</span>'; 
    echo '<span style="float:right; width:100px; text-align:right;"> <strong>'.$perm.'</strong></span>'; 
    echo '<span style="float:right; padding-right:100px;"><strong>'.$configmod.'</strong></span>'; 
    echo '<div class="clear"></div>'; 
    echo "</li>"; 

} 
    check_perms("config.php","0777"); 
    check_perms("themes","0777"); 
    check_perms("themes/images","0777"); 
    check_perms("useruploads","0777"); 
?> 
</ul> 

如何使所有文件和文件夾有效的權限爲777會出現Submit button

<input type='submit' name='submit' value='Submit' /> 

如果仍然有不正確的權限沒有顯示提交按鈕

讓我知道。

回答

1

呃,這將是一個有點髒,但:

<?php 

$error=0; 
function check_perms($path,$perm) 
{ 
    global $error; 
    clearstatcache(); 
    $configmod = substr(sprintf('%o', fileperms($path)), -4); 
    $css = (($configmod != $perm) ? " class='error'" : " class='none'"); 
    if($configmod != $perm) $error++; 
    echo "<li".$css.">\n"; 
    echo '<span style="float:left; padding-right:20px;">'.$path.'</span>'; 
    echo '<span style="float:right; width:100px; text-align:right;"> <strong>'.$perm.'</strong></span>'; 
    echo '<span style="float:right; padding-right:100px;"><strong>'.$configmod.'</strong></span>'; 
    echo '<div class="clear"></div>'; 
    echo "</li>"; 

} 
    check_perms("config.php","0777"); 
    check_perms("themes","0777"); 
    check_perms("themes/images","0777"); 
    check_perms("useruploads","0777"); 

    if($error > 0) echo 'Dude, fix the permissions!'; 
    else echo '<input type="submit">'; 
    ?> 
+0

但它的工作!感謝Robus。髒了? – wow 2010-05-09 02:06:51