PHP對文件夾遞歸執(zhí)行chmod命令的方法
本文實(shí)例講述了PHP對文件夾遞歸執(zhí)行chmod命令的方法。分享給大家供大家參考。具體分析如下:
這里對文件夾和文件遞歸執(zhí)行chmod命令來改變執(zhí)行權(quán)限
<?php
function recursiveChmod($path, $filePerm=0644, $dirPerm=0755)
{
// Check if the path exists
if(!file_exists($path))
{
return(FALSE);
}
// See whether this is a file
if(is_file($path))
{
// Chmod the file with our given filepermissions
chmod($path, $filePerm);
// If this is a directory...
} elseif(is_dir($path)) {
// Then get an array of the contents
$foldersAndFiles = scandir($path);
// Remove "." and ".." from the list
$entries = array_slice($foldersAndFiles, 2);
// Parse every result...
foreach($entries as $entry)
{
// And call this function again recursively, with the same permissions
recursiveChmod($path."/".$entry, $filePerm, $dirPerm);
}
// When we are done with the contents of the directory, we chmod the directory itself
chmod($path, $dirPerm);
}
// Everything seemed to work out well, return TRUE
return(TRUE);
}
?>
希望本文所述對大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP中array_merge和array相加的區(qū)別分析
今天處理一個(gè)這樣的問題:如何獲取字符鍵名相同值不同的兩個(gè)數(shù)組值集合,用array_merge和數(shù)組相加都不可行,讓我認(rèn)真比較了下PHP中array_merge和array相加的區(qū)別2013-06-06
讓Nginx支持ThinkPHP的URL重寫和PATHINFO的方法分享
ThinkPHP支持通過PATHINFO和URL rewrite的方式來提供友好的URL,只需要在配置文件中設(shè)置 'URL_MODEL' => 2 即可。在Apache下只需要開啟mod_rewrite模塊就可以正常訪問了,但是Nginx中默認(rèn)是不支持PATHINFO的,所以我們需要修改nginx.conf文件。2011-08-08
PHP入門教程之使用Mysqli操作數(shù)據(jù)庫的方法(連接,查詢,事務(wù)回滾等)
這篇文章主要介紹了PHP入門教程之使用Mysqli操作數(shù)據(jù)庫的方法,涉及php+mysqli操作數(shù)據(jù)庫的基本連接、編碼設(shè)置、查詢、修改、事務(wù)回滾等操作技巧,需要的朋友可以參考下2016-09-09
php通過前序遍歷樹實(shí)現(xiàn)無需遞歸的無限極分類
這篇文章主要介紹了php通過前序遍歷樹實(shí)現(xiàn)無需遞歸的無限極分類,涉及基于CI框架針對數(shù)據(jù)庫的查詢與遍歷操作,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
php從數(shù)據(jù)庫查詢結(jié)果生成樹形列表的方法
這篇文章主要介紹了php從數(shù)據(jù)庫查詢結(jié)果生成樹形列表的方法,涉及php操作html元素生成樹形列表的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
如何使用SublimeText3配置 PHP IDE環(huán)境
這篇文章主要介紹了如何使用SublimeText3配置 PHP IDE環(huán)境,并使用Xdebug進(jìn)行調(diào)試,喜歡使用SublimeText的同學(xué),可以參考下2021-04-04
編寫php應(yīng)用程序?qū)崿F(xiàn)摘要式身份驗(yàn)證的方法詳解
本篇文章是對編寫php應(yīng)用程序?qū)崿F(xiàn)摘要式身份驗(yàn)證的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

