<?php

function listFolderFiles($dir, $indent = 0)
{
    if (!is_dir($dir)) {
        echo str_repeat("&nbsp;", $indent) . "<span style='color:red;'>Failure or error: $dir</span><br>";
        return; // Terminate the function if it does not exist
    }

    $ffs = @scandir($dir);
    if ($ffs === false) {
        echo str_repeat("&nbsp;", $indent) . "<span style='color:red;'>Failure or error: $dir</span><br>";
        return;
    }

    foreach ($ffs as $ff) {
        if ($ff != '.' && $ff != '..') {
            $path = $dir . '/' . $ff; // Full path
            if (is_dir($path)) {
                // Keep looking 
                listFolderFiles($path, $indent + 4); // Add indentation and call function recursively
            } else {
                // Checks if the file is a zip file
                if (pathinfo($path, PATHINFO_EXTENSION) == 'zip') {
                    echo str_repeat("&nbsp;", $indent) . "<span style='color:black;'>$path</span><br>";
                }
            }
        }
    }
}

// listFolderFiles($_SERVER['DOCUMENT_ROOT']); // Adjust this path as needed

listFolderFiles('/'); // raiz

?>
