PHP對(duì)文件夾遞歸執(zhí)行chmod命令的方法
本文實(shí)例講述了PHP對(duì)文件夾遞歸執(zhí)行chmod命令的方法。分享給大家供大家參考。具體分析如下:
這里對(duì)文件夾和文件遞歸執(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); } ?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
php實(shí)現(xiàn)的支持?jǐn)帱c(diǎn)續(xù)傳的文件下載類
這篇文章主要介紹了php實(shí)現(xiàn)的支持?jǐn)帱c(diǎn)續(xù)傳的文件下載類及其用法實(shí)例,詳細(xì)講述了PHP實(shí)現(xiàn)斷點(diǎn)續(xù)傳下載的原理及代碼實(shí)現(xiàn)方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-09-09php使用escapeshellarg時(shí)中文被過濾的解決方法
這篇文章主要介紹了php使用escapeshellarg時(shí)中文被過濾的解決方法,測試后發(fā)現(xiàn)問題的原因是shell和apache php-cgi的運(yùn)行環(huán)境不同引起的,需要的朋友可以參考下2016-07-07PHP常用工具函數(shù)小結(jié)【移除XSS攻擊、UTF8與GBK編碼轉(zhuǎn)換等】
這篇文章主要介紹了PHP常用工具函數(shù),結(jié)合實(shí)例形式總結(jié)分析了php移除XSS攻擊、以及php操作UTF8與GBK編碼轉(zhuǎn)換等相關(guān)操作自定義函數(shù)實(shí)現(xiàn)方法,需要的朋友可以參考下2019-04-04phpadmin如何導(dǎo)入導(dǎo)出大數(shù)據(jù)文件及php.ini參數(shù)修改
新版本的phpadmin導(dǎo)入限定是8M,老版本的可能2M;如果遇到幾十兆的該怎么辦呢?接下來本文將介紹詳細(xì)的修改方法,感興趣的你可不要錯(cuò)過了哈,或許本文提供的知識(shí)點(diǎn)對(duì)你有所幫助2013-02-02PHP實(shí)現(xiàn)通過正則表達(dá)式替換回調(diào)的內(nèi)容標(biāo)簽
這篇文章主要介紹了PHP實(shí)現(xiàn)通過正則表達(dá)式替換回調(diào)的內(nèi)容標(biāo)簽的方法,涉及php正則匹配與替換的相關(guān)技巧,需要的朋友可以參考下2015-06-06