当前位置:Gxlcms > PHP教程 > PHP递归对文件夹递归执行chmod命令

PHP递归对文件夹递归执行chmod命令

时间:2021-07-01 10:21:17 帮助过:18人阅读

  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

人气教程排行