exec ("find /path/to/folder -type f -exec chmod 0777 {} +"); - папки
exec ("find /path/to/folder -type d -exec chmod 0777 {} +"); - файлы
<?php
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pathname));
foreach($iterator as $item) {
chmod($item, $filemode);
}
?>