function recursiveChmod($path, $filePerm = 0644, $dirPerm = 0755)
{
    if (!file_exists($path)) {
        return false;
    }
    if (is_file($path)) {
        chmod($path, $filePerm);
    } elseif (is_dir($path)) {
        $foldersAndFiles = scandir($path);
        $entries = array_slice($foldersAndFiles, 2);
        foreach ($entries as $entry) {
            recursiveChmod($path . "/" . $entry, $filePerm, $dirPerm);
        }
        chmod($path, $dirPerm);
    }
    return true;
}
function recursiveChmod($path, $recursively, $filesChange, $foldersChange, $filesPerm, $foldersPerm)
{
    echo "Changing {$path} with folder perms: {$foldersPerm} and file perms: {$filesPerm}\n";
    if (!file_exists($path)) {
        echo "File {$path} does not exists!";
        return false;
    }
    if (is_file($path)) {
        if ($filesChange) {
            chmod($path, octdec($filesPerm));
            echo "Changed file permissions to " . $filesPerm . " on file {$path}.\n";
        }
    } elseif (is_dir($path)) {
        if ($recursively) {
            $foldersAndFiles = scandir($path);
            $entries = array_slice($foldersAndFiles, 2);
            foreach ($entries as $entry) {
                recursiveChmod($path . "/" . $entry, $recursively, $filesChange, $foldersChange, $filesPerm, $foldersPerm);
            }
        }
        // When we are done with the contents of the directory, we chmod the directory itself
        if ($foldersChange) {
            chmod($path, octdec($foldersPerm));
            echo "Changed directory permissions to " . $foldersPerm . " on directory {$path}.\n";
        }
    }
    return true;
}
Esempio n. 3
0
function recursiveChmod($path, $filePerm = 0644, $dirPerm = 0755)
{
    // Check if the path exists
    if (!file_exists($path)) {
        return FALSE;
    }
    // See whether this is a file
    if (is_file($path)) {
        // Chmod the file with our given filepermissions
        chmod($path, $filePerm);
        // If this is a directory...
    } elseif (is_dir($path)) {
        // Then get an array of the contents
        $foldersAndFiles = scandir($path);
        // Remove "." and ".." from the list
        $entries = array_slice($foldersAndFiles, 2);
        // Parse every result...
        foreach ($entries as $entry) {
            // And call this function again recursively, with the same permissions
            recursiveChmod($path . "/" . $entry, $filePerm, $dirPerm);
        }
        // When we are done with the contents of the directory, we chmod the directory itself
        chmod($path, $dirPerm);
    }
    // Everything seemed to work out well, return TRUE
    return TRUE;
}