欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-03 21:18:51
...
  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