Advertisement
Russell

PHP Script for Recursive 755 + 644

Dec 27th, 2021
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?
  2.  
  3.   header('Content-Type: text/plain');
  4.  
  5.   /**
  6.   * Changes permissions on files and directories within $dir and dives
  7.   * recursively into found subdirectories.
  8.   */
  9.  
  10.   function chmod_r($dir, $dirPermissions, $filePermissions) {
  11.       $dp = opendir($dir);
  12.        while($file = readdir($dp)) {
  13.          if (($file == ".") || ($file == ".."))
  14.             continue;
  15.  
  16.         $fullPath = $dir."/".$file;
  17.  
  18.          if(is_dir($fullPath)) {
  19.             echo('DIR:' . $fullPath . "\n");
  20.             chmod($fullPath, $dirPermissions);
  21.             chmod_r($fullPath, $dirPermissions, $filePermissions);
  22.          } else {
  23.             echo('FILE:' . $fullPath . "\n");
  24.             chmod($fullPath, $filePermissions);
  25.          }
  26.  
  27.        }
  28.      closedir($dp);
  29.   }
  30.  
  31.   chmod_r(dirname(__FILE__), 0755, 0644);
  32.  
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement