首頁 >後端開發 >php教程 >PHP遞歸對資料夾遞歸執行chmod指令

PHP遞歸對資料夾遞歸執行chmod指令

WBOY
WBOY原創
2016-07-25 08:45:05929瀏覽
  1. function recursiveChmod($path, $filePerm=0644, $dirPerm=0755)
  2. {
  3. // Check if the path exists
  4. if(!file_exists($path))
  5. {
  6. return(FALSE);
  7. }
  8. // See whether this is a file
  9. if(is_file($path))
  10. {
  11. // Chmod the file with our given filepermissions
  12. chmod($path, $filePerm);
  13. // If this is a directory...
  14. } elseif(is_dir($path)) {
  15. // Then get an array of the contents
  16. $foldersAndFiles = scandir($path);
  17. // Remove "." and ".." from the list
  18. $entries = array_slice($foldersAndFiles, 2);
  19. // Parse every result...
  20. foreach($entries as $entry)
  21. {
  22. // And call this function again recursively, with the same permissions
  23. recursiveChmod($path."/".$entry, $filePerm, $dirPerm);
  24. }
  25. // When we are done with the contents of the directory, we chmod the directory itself
  26. chmod($path, $dirPerm);
  27. }
  28. // Everything seemed to work out well, return TRUE
  29. return(TRUE);
  30. }
  31. ?>
复制代码

PHP、chmod


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn