File: /home/pioneercabinetry/.trash/permfix1.php
<?php
header('Content-Type: text/plain');
/**
* Recursively changes permissions of files and directories within $dir and all subdirectories.
* Original script by XDude: http://www.xdude.com/
*/
function chmod_r(string $dir): void
{
$files = scandir($dir);
if ($files === false) {
echo "Failed to read directory: $dir\n";
return;
}
foreach ($files as $file) {
if ($file === "." || $file === "..") {
continue;
}
$path = $dir . DIRECTORY_SEPARATOR . $file;
$is_dir = is_dir($path);
set_perms($path, $is_dir);
if ($is_dir) {
chmod_r($path);
}
}
}
function set_perms(string $file, bool $is_dir): void
{
$perm = fileperms($file);
if ($perm === false) {
echo "Failed to get permissions for: $file\n";
return;
}
$perm = substr(sprintf("%o", $perm), -4);
$dirPermissions = "0755";
$filePermissions = "0644";
if ($is_dir && $perm !== $dirPermissions) {
echo "Dir: $file\n";
chmod($file, 0755);
} elseif (!$is_dir && $perm !== $filePermissions) {
echo "File: $file\n";
chmod($file, 0644);
}
flush();
}
chmod_r(__DIR__);
?>