set recursive permission to all file and folder from current directory of file.

set recursive permission to all file and folder from current directory of file.

July 29, 2018 PHP SugarCRM 0

<?

 header('Content-Type: text/plain');

 /**
 * Changes permissions on files and directories within $dir and dives recursively
 * into found subdirectories.
 */
 function chmod_r($dir, $dirPermissions, $filePermissions) {
     $dp = opendir($dir);
      while($file = readdir($dp)) {
        if (($file == ".") || ($file == ".."))
           continue;

       $fullPath = $dir."/".$file;

        if(is_dir($fullPath)) {
           echo('DIR:' . $fullPath . "\n");
           chmod($fullPath, $dirPermissions);
           chmod_r($fullPath, $dirPermissions, $filePermissions);
        } else {
           echo('FILE:' . $fullPath . "\n");
           chmod($fullPath, $filePermissions);
        }

      }
    closedir($dp);
 }

 chmod_r(dirname(__FILE__), 0755, 0755);
 
?>

****note:  if you have set wrong permission in cpanel and want set permission but no access for php and ssh then

 

go to cpanel home and in cron job:

 

set line like :

 

chmod -R 755 $(find /user/home/public_html/crm/ -type d)  <= d means directory

 

Leave a Reply

Your email address will not be published. Required fields are marked *