php 對資料夾遞歸執行chmod指令的方法詳解

怪我咯
發布: 2023-03-12 18:08:02
原創
1420 人瀏覽過

這篇文章主要介紹了PHP對資料夾遞歸執行chmod指令的方法,可實現遞歸執行chmod指令改變資料夾執行權限的功能,需要的朋友可以參考下

本文實例講述了PHP對資料夾遞歸執行chmod指令的方法。分享給大家供大家參考。具體分析如下:

這裡對資料夾和檔案遞歸執行chmod指令來改變執行權限

<?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 對資料夾遞歸執行chmod指令的方法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!