GetSimple Support Forum
Recursive CHMOD function - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Scripts & Components (http://get-simple.info/forums/forumdisplay.php?fid=11)
+--- Thread: Recursive CHMOD function (/showthread.php?tid=1114)



Recursive CHMOD function - ccagle8 - 2010-11-12

I wrote this a while back for something (i cant remember why now) but figured that I would share. use at your own discretion, but it does work. It can probably be better written and account for trying 0777 when 0755 fails, etc. But here it is...


Recursive CHMOD function - Oleg06 - 2010-11-12

but where it is inserted to check?


Recursive CHMOD function - ccagle8 - 2010-11-12

sorry, put it in the {root}


RE: Recursive CHMOD function - akd - 2014-08-26

(2010-11-12, 13:09:28)ccagle8 Wrote: I wrote this a while back for something (i cant remember why now) but figured that I would share. use at your own discretion, but it does work. It can probably be better written and account for trying 0777 when 0755 fails, etc. But here it is...

Where the script get lost?.... we still need it......


RE: Recursive CHMOD function - shawn_a - 2014-08-26

interesting, I didn't know this existed, i was planning on making one.


RE: Recursive CHMOD function - shawn_a - 2014-08-27

I found this in the archives

PHP Code:
<?php




$chmod_mode 
0755#no quotes around this number


/**
 * Recursive CHMOD
 *
 * @since 2.04
 * @author ccagle8
 *
 * @param string $path
 * @param string $filemode
 * @return bool
 */
function chmodr($path$filemode){
    if (!
is_dir($path)) {
        return 
chmod($path$filemode);
         }
    
$dh opendir($path);
    while ((
$file readdir($dh)) !== false)    {
        if (
$file != '.' && $file != '..')        {
            
$fullpath $path.'/'.$file;
            if(
is_link($fullpath)) {
                return 
FALSE;
            } elseif(!
is_dir($fullpath) && !chmod($fullpath$filemode)) {
                return 
FALSE;
            } elseif(!
chmodr($fullpath$filemode)) {
                return 
FALSE;
            }
        }
    }
 
    
closedir($dh);
 
    if(
chmod($path$filemode)) {
        return 
TRUE;
    } else {
        return 
FALSE;
    }
}




if (!isset(
$_GET['attemptfix'])) {
    echo 
"<html><head><title>Attempt to Fix</title></head><body>";
    echo 
'<a href="fix.php?attemptfix">Attempt to Fix</a>';
    echo 
"</body></html>";
} else {
    
$data_folder_status chmodr('data'$chmod_mode);
    
$backup_folder_status chmodr('backups'$chmod_mode);
    
    
$htaccess_folder_status chmod('temp.htaccess'$chmod_mode);
    
$gsconfig_folder_status chmod('temp.gsconfig.php'$chmod_mode);
    
    if (
$data_folder_status) {
        
$fix_status .= "Data path successfully chmod'd. <br />";
    } else {
        
$fix_status .= "Cannot chmod data path - Please do it manually. <br />";
    }
    
    if (
$data_folder_status) {    
        
$fix_status .= "Backup path successfully chmod'd. <br />";
    } else {
        
$fix_status .= "Cannot chmod backup path - Please do it manually. <br />";
    }
    
    if (
$htaccess_folder_status) {    
        
$fix_status .= ".htaccess successfully chmod'd. <br />";
        
copy('temp.htaccess''.htaccess');
        
chmod('.htaccess'$chmod_mode);
    } else {
        
$fix_status .= "Cannot chmod .htaccess - Please do it manually. <br />";
    }
    
    if (
$gsconfig_folder_status) {    
        
$fix_status .= "gsconfig.php successfully chmod'd. <br />";
        
copy('temp.gsconfig.php''gsconfig.php');
        
chmod('gsconfig.php'$chmod_mode);
    } else {
        
$fix_status .= "Cannot chmod gsconfig.php - Please do it manually. <br />";
    }    

    echo 
$fix_status;
}



?>



RE: Recursive CHMOD function - akd - 2014-08-29

wow. perfect. Thanks!


RE: Recursive CHMOD function - shawn_a - 2014-08-29

not tested of course