MOON
Server: Apache
System: Linux p3plzcpnl504823.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: pioneercabinetry (3950193)
PHP: 8.2.30
Disabled: NONE
Upload Files
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__);
?>