| <?php |
| ini_set('display_errors', 1); |
| ini_set('display_startup_errors', 1); |
| error_reporting(E_ALL); |
|
|
| session_start(); |
| if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) { |
| header('Location: ../../index.php'); |
| exit; |
| } |
|
|
| |
| $username = $_SESSION['username'] ?? 'Guest'; |
| $email = $_SESSION['email'] ?? ''; |
| $tier = $_SESSION['tier'] ?? 'Free'; |
| $package = $_SESSION['package'] ?? ''; |
| $balance = $_SESSION['balance'] ?? 0.00; |
| $total_deposits = $_SESSION['total_deposits'] ?? 0.00; |
| $total_withdrawals = $_SESSION['total_withdrawals'] ?? 0.00; |
| $rewards = $_SESSION['rewards'] ?? 0.00; |
| $meta_earnings = $_SESSION['meta_earnings'] ?? 0.00; |
|
|
| |
| if (!isset($_SESSION['user_id'])) { |
| $_SESSION['user_id'] = 1; |
| } |
| $userId = $_SESSION['user_id'] ?? 1; |
|
|
| |
| function getDBConnection() { |
| $host = '127.0.0.1'; |
| $dbname = 'jweb'; |
| $username = 'root'; |
| $password = 'YourStrongPassword123'; |
| |
| try { |
| $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password); |
| $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| return $pdo; |
| } catch (PDOException $e) { |
| die("Database connection failed: " . $e->getMessage()); |
| } |
| } |
|
|
| |
| $uploadDir = __DIR__ . '/uploads/'; |
|
|
| |
| $uploadDirCreated = false; |
| if (!is_dir($uploadDir)) { |
| if (!mkdir($uploadDir, 0755, true)) { |
| |
| $uploadDir = '/tmp/jweb_uploads/'; |
| if (!is_dir($uploadDir) && !mkdir($uploadDir, 0755, true)) { |
| $uploadError = "❌ Failed to create upload directory. Please contact administrator to fix permissions."; |
| } else { |
| $uploadDirCreated = true; |
| } |
| } else { |
| $uploadDirCreated = true; |
| } |
| } else { |
| $uploadDirCreated = true; |
| } |
|
|
| |
| if ($uploadDirCreated && !is_writable($uploadDir)) { |
| if (!chmod($uploadDir, 0755)) { |
| $uploadError = "❌ Upload directory is not writable. Please fix permissions for: " . $uploadDir; |
| $uploadDirCreated = false; |
| } |
| } |
|
|
| |
| $uploadResults = []; |
| if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['uploaded_files']) && $uploadDirCreated) { |
| foreach ($_FILES['uploaded_files']['name'] as $key => $name) { |
| if ($_FILES['uploaded_files']['error'][$key] === UPLOAD_ERR_OK) { |
| $fileType = $_FILES['uploaded_files']['type'][$key]; |
| $fileSize = $_FILES['uploaded_files']['size'][$key]; |
| $tmpName = $_FILES['uploaded_files']['tmp_name'][$key]; |
|
|
| |
| $allowedTypes = ['image/jpeg', 'image/png', 'video/mp4', 'application/pdf']; |
| $maxSize = 50 * 1024 * 1024; |
|
|
| if (in_array($fileType, $allowedTypes) && $fileSize <= $maxSize) { |
| |
| $extension = pathinfo($name, PATHINFO_EXTENSION); |
| $filename = uniqid("file_", true) . '.' . $extension; |
| $filePath = $uploadDir . $filename; |
|
|
| if (move_uploaded_file($tmpName, $filePath)) { |
| |
| $reward = calculateReward($fileType, $fileSize); |
| |
| |
| if (saveUploadToDB($userId, $name, $fileType, $fileSize, $filePath, $reward)) { |
| $uploadResults[] = [ |
| 'success' => true, |
| 'name' => $name, |
| 'reward' => $reward |
| ]; |
| |
| |
| updateUserBalance($userId, $reward); |
| } else { |
| $uploadResults[] = [ |
| 'success' => false, |
| 'name' => $name, |
| 'error' => 'Database error' |
| ]; |
| } |
| } else { |
| $uploadResults[] = [ |
| 'success' => false, |
| 'name' => $name, |
| 'error' => '❌ Cannot move uploaded file. Check folder permissions.' |
| ]; |
| } |
| } else { |
| $uploadResults[] = [ |
| 'success' => false, |
| 'name' => $name, |
| 'error' => 'Invalid file type or file too large' |
| ]; |
| } |
| } else { |
| $uploadResults[] = [ |
| 'success' => false, |
| 'name' => $name, |
| 'error' => 'Upload error: ' . $_FILES['uploaded_files']['error'][$key] |
| ]; |
| } |
| } |
|
|
| |
| refreshUserSession($userId, $uploadResults); |
| } |
|
|
| |
| function calculateReward($fileType, $fileSize) { |
| $baseReward = 50; |
| |
| if (strpos($fileType, 'image/') === 0) { |
| $baseReward = 60; |
| } elseif (strpos($fileType, 'video/') === 0) { |
| $baseReward = 85; |
| } elseif ($fileType === 'application/pdf') { |
| $baseReward = 55; |
| } |
| |
| |
| if ($fileSize > 10 * 1024 * 1024) { |
| $baseReward += 10; |
| } |
| |
| return $baseReward; |
| } |
|
|
| |
| function saveUploadToDB($userId, $fileName, $fileType, $fileSize, $filePath, $reward) { |
| try { |
| $pdo = getDBConnection(); |
| $stmt = $pdo->prepare("INSERT INTO uploads (user_id, file_name, file_type, file_size, file_path, reward_amount, status) |
| VALUES (?, ?, ?, ?, ?, ?, 'pending')"); |
| return $stmt->execute([$userId, $fileName, $fileType, $fileSize, $filePath, $reward]); |
| } catch (PDOException $e) { |
| error_log("Database error: " . $e->getMessage()); |
| return false; |
| } |
| } |
|
|
| |
| function updateUserBalance($userId, $reward) { |
| try { |
| $pdo = getDBConnection(); |
| |
| |
| $stmt = $pdo->prepare("UPDATE users SET balance = balance + ?, rewards = rewards + ?, meta_earnings = meta_earnings + ? WHERE id = ?"); |
| $stmt->execute([$reward, $reward, $reward, $userId]); |
| |
| return true; |
| } catch (PDOException $e) { |
| error_log("Database error: " . $e->getMessage()); |
| return false; |
| } |
| } |
|
|
| |
| function refreshUserSession($userId, $uploadResults = []) { |
| $totalReward = 0; |
| |
| foreach ($uploadResults as $result) { |
| if ($result['success']) { |
| $totalReward += $result['reward']; |
| } |
| } |
| |
| if ($totalReward > 0) { |
| $_SESSION['balance'] = ($_SESSION['balance'] ?? 0) + $totalReward; |
| $_SESSION['rewards'] = ($_SESSION['rewards'] ?? 0) + $totalReward; |
| $_SESSION['meta_earnings'] = ($_SESSION['meta_earnings'] ?? 0) + $totalReward; |
| |
| |
| global $balance, $rewards, $meta_earnings; |
| $balance = $_SESSION['balance']; |
| $rewards = $_SESSION['rewards']; |
| $meta_earnings = $_SESSION['meta_earnings']; |
| } |
| } |
|
|
| |
| function getTodaysUploads($userId) { |
| try { |
| $pdo = getDBConnection(); |
| $stmt = $pdo->prepare("SELECT * FROM uploads WHERE user_id = ? AND DATE(created_at) = CURDATE() ORDER BY created_at DESC"); |
| $stmt->execute([$userId]); |
| return $stmt->fetchAll(PDO::FETCH_ASSOC); |
| } catch (PDOException $e) { |
| error_log("Database error: " . $e->getMessage()); |
| return []; |
| } |
| } |
|
|
| |
| function getTodaysUploadStats($userId) { |
| try { |
| $pdo = getDBConnection(); |
| $stmt = $pdo->prepare("SELECT |
| COUNT(*) as total_uploads, |
| SUM(CASE WHEN status = 'approved' THEN 1 ELSE 0 END) as approved_uploads, |
| SUM(CASE WHEN status = 'approved' THEN reward_amount ELSE 0 END) as total_earnings |
| FROM uploads |
| WHERE user_id = ? AND DATE(created_at) = CURDATE()"); |
| $stmt->execute([$userId]); |
| return $stmt->fetch(PDO::FETCH_ASSOC); |
| } catch (PDOException $e) { |
| error_log("Database error: " . $e->getMessage()); |
| return ['total_uploads' => 0, 'approved_uploads' => 0, 'total_earnings' => 0]; |
| } |
| } |
|
|
| |
| if (!empty($uploadResults)) { |
| $successCount = 0; |
| $errorCount = 0; |
| $totalReward = 0; |
| |
| foreach ($uploadResults as $result) { |
| if ($result['success']) { |
| $successCount++; |
| $totalReward += $result['reward']; |
| } else { |
| $errorCount++; |
| } |
| } |
| |
| if ($successCount > 0) { |
| $message = "Successfully uploaded $successCount files. Earned KES " . number_format($totalReward, 2); |
| } |
| |
| if ($errorCount > 0) { |
| $error = "Failed to upload $errorCount files."; |
| } |
| } |
|
|
| |
| $todaysUploads = getTodaysUploads($userId); |
| $uploadStats = getTodaysUploadStats($userId); |
| $totalUploads = $uploadStats['total_uploads'] ?? 0; |
| $approvedUploads = $uploadStats['approved_uploads'] ?? 0; |
| $todaysEarnings = $uploadStats['total_earnings'] ?? 0; |
|
|
| |
| function getFileIcon($fileType) { |
| if (strpos($fileType, 'image/') === 0) return 'image'; |
| if (strpos($fileType, 'video/') === 0) return 'video'; |
| if ($fileType === 'application/pdf') return 'file-text'; |
| return 'file'; |
| } |
|
|
| function formatFileSize($bytes) { |
| if ($bytes == 0) return '0 Bytes'; |
| $k = 1024; |
| $sizes = ['Bytes', 'KB', 'MB', 'GB']; |
| $i = floor(log($bytes) / log($k)); |
| return round($bytes / pow($k, $i), 2) . ' ' . $sizes[$i]; |
| } |
| ?> |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>Japanese Motors — Uploads</title> |
| <script src="https://cdn.tailwindcss.com"></script> |
| <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700;800&display=swap" rel="stylesheet"> |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> |
| <style> |
| :root { |
| --bg: |
| --card: |
| --card-2: |
| --accent: |
| --muted: rgba(255,255,255,0.6); |
| --glass: rgba(255,255,255,0.04); |
| --promo-gradient: linear-gradient(180deg,#a13df0 0%, #ff2a79 50%, #d70b1a 100%); |
| font-family: 'Poppins', system-ui, Arial; |
| --banner-gradient-start: |
| --banner-gradient-end: |
| --spacing-unit: 1rem; |
| --accent-primary: |
| --accent-secondary: |
| --shadow-hover: 0 6px 18px rgba(0, 0, 0, 0.1); |
| --premium-gold: |
| } |
| |
| body { |
| background: var(--bg); |
| font-family: 'Poppins', sans-serif; |
| transition: all 0.3s ease; |
| min-height: 100vh; |
| } |
| |
| .sidebar { |
| width: 250px; |
| height: 100vh; |
| background: |
| color: |
| position: fixed; |
| top: 0; |
| left: -250px; |
| transition: all 0.3s ease; |
| z-index: 1000; |
| overflow-y: auto; |
| } |
| |
| .sidebar.active { |
| left: 0; |
| } |
| |
| |
| margin-left: 0; |
| transition: all 0.3s ease; |
| } |
| |
| .sidebar.active ~ |
| margin-left: 250px; |
| } |
| |
| header { |
| background: |
| color: white; |
| padding: 15px 20px; |
| display: flex; |
| justify-content: space-between; |
| align-items: center; |
| position: relative; |
| z-index: 900; |
| transition: all 0.3s ease; |
| } |
| |
| .sidebar.active ~ |
| margin-left: 250px; |
| } |
| |
| .menu-toggle { |
| background: transparent; |
| border: none; |
| color: white; |
| font-size: 1.5rem; |
| cursor: pointer; |
| } |
| |
| .logo-section { |
| padding: 15px; |
| border-bottom: 1px solid |
| display: flex; |
| align-items: center; |
| gap: 10px; |
| } |
| |
| .brand { |
| font-size: 1.2rem; |
| font-weight: 700; |
| color: |
| } |
| |
| .subtitle { |
| font-size: 0.75rem; |
| color: |
| } |
| |
| .menu { |
| list-style: none; |
| padding: 0; |
| margin: 0; |
| } |
| |
| .menu li a { |
| display: flex; |
| align-items: center; |
| padding: 12px 20px; |
| color: white; |
| text-decoration: none; |
| transition: background 0.3s; |
| } |
| |
| .menu li a:hover { |
| background: |
| } |
| |
| .menu li a i { |
| margin-right: 12px; |
| } |
| |
| .user-footer { |
| padding: 15px; |
| background: |
| display: flex; |
| align-items: center; |
| gap: 10px; |
| position: sticky; |
| bottom: 0; |
| } |
| |
| .avatar { |
| width: 35px; |
| height: 35px; |
| background: |
| border-radius: 50%; |
| display: flex; |
| align-items: center; |
| justify-content: center; |
| font-weight: bold; |
| color: white; |
| } |
| |
| .banner { |
| max-width: 450px; |
| margin: 0 auto calc(var(--spacing-unit) * 2); |
| background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary)); |
| border-radius: 12px; |
| padding: calc(var(--spacing-unit) * 1.5); |
| text-align: center; |
| box-shadow: var(--shadow-hover); |
| animation: fadeIn 0.5s ease; |
| } |
|
|
| @keyframes fadeIn { |
| from { opacity: 0; transform: translateY(20px); } |
| to { opacity: 1; transform: translateY(0); } |
| } |
|
|
| @keyframes blink { |
| 0% { opacity: 1; } |
| 50% { opacity: 0.3; } |
| 100% { opacity: 1; } |
| } |
|
|
| .banner .title { |
| font-size: 1.25rem; |
| margin-bottom: calc(var(--spacing-unit) * 1); |
| color: |
| font-weight: 700; |
| animation: blink 1.5s infinite; |
| } |
|
|
| .banner p { |
| font-size: 0.95rem; |
| line-height: 1.6; |
| margin-bottom: calc(var(--spacing-unit) * 1); |
| color: var(--premium-gold); |
| animation: blink 1.5s infinite; |
| } |
|
|
| .banner .footer { |
| font-size: 0.75rem; |
| color: rgba(255, 255, 255, 0.9); |
| font-style: italic; |
| animation: blink 1.5s infinite; |
| } |
| |
| .card { |
| background: var(--card); |
| border-radius: 12px; |
| padding: 26px; |
| color: white; |
| box-shadow: 0 6px 0 rgba(0,0,0,0.08) inset; |
| flex: 1; |
| } |
| |
| .upload-area { |
| border: 2px dashed rgba(255,255,255,0.2); |
| border-radius: 12px; |
| padding: 40px; |
| text-align: center; |
| cursor: pointer; |
| transition: all 0.3s; |
| } |
| |
| .upload-area:hover { |
| border-color: var(--accent); |
| background: rgba(255,255,255,0.03); |
| } |
| |
| .btn { |
| display: inline-block; |
| padding: 14px 24px; |
| border-radius: 10px; |
| background: var(--accent); |
| color: |
| font-weight: 700; |
| border: none; |
| cursor: pointer; |
| width: 100%; |
| } |
| |
| .btn:disabled { |
| background: |
| cursor: not-allowed; |
| } |
| |
| .upload-item { |
| background: rgba(0,0,0,0.2); |
| border-radius: 8px; |
| padding: 12px; |
| margin-bottom: 10px; |
| display: flex; |
| align-items: center; |
| justify-content: space-between; |
| } |
| |
| @media (max-width: 768px) { |
| .cards { |
| flex-direction: column; |
| } |
| |
| .promo { |
| width: 92%; |
| } |
| } |
| </style> |
| </head> |
| <body> |
| <!-- Sidebar --> |
| <aside class="sidebar" id="sidebar"> |
| <div class="logo-section"> |
| <i data-feather="zap" class="text-yellow-400"></i> |
| <div> |
| <h2 class="brand">JMOTORS</h2> |
| <p class="subtitle">Marketing Platform</p> |
| </div> |
| </div> |
| |
| <ul class="menu"> |
| <li><a href="index.php"><i data-feather="home"></i> Dashboard</a></li> |
| <li><a href="meta-uploads.php" class="active-page"><i data-feather="upload"></i> Meta Uploads</a></li> |
| <li><a href="transactions.php"><i data-feather="repeat"></i> Transactions</a></li> |
| <li><a href="transfer.php"><i data-feather="send"></i> Transfer</a></li> |
| <li><a href="daily-product.php"><i data-feather="shopping-bag"></i> Daily Product</a></li> |
| <li><a href="withdraw.php"><i data-feather="dollar-sign"></i> Withdraw</a></li> |
| <li><a href="packages.php"><i data-feather="package"></i> Packages</a></li> |
| <li><a href="loan.php"><i data-feather="credit-card"></i> Loan</a></li> |
| <li><a href="recharge.php"><i data-feather="battery-charging"></i> Recharge</a></li> |
| <li><a href="agent-approval.php"><i data-feather="user-check"></i> Agent Approval</a></li> |
| <li><a href="access-token.php"><i data-feather="key"></i> Access Token</a></li> |
| <li><a href="agent-claim.php"><i data-feather="tag"></i> Agent Claim</a></li> |
| <li><a href="team.php"><i data-feather="users"></i> Team</a></li> |
| </ul> |
| |
| <ul class="menu bottom"> |
| <li><a href="profile.php"><i data-feather="user"></i> Profile</a></li> |
| <li><a href="settings.php"><i data-feather="settings"></i> Settings</a></li> |
| <li><a href="whatsapp-channel.php"><i data-feather="message-square"></i> Whatsapp Channel</a></li> |
| <li><a href="customer-care.php"><i data-feather="headphones"></i> Customer Care</a></li> |
| </ul> |
| |
| <div class="user-footer"> |
| <div class="avatar"><?php echo substr($username, 0, 2); ?></div> |
| <div> |
| <h4><?php echo $username; ?></h4> |
| <p><?php echo $tier; ?> - Marketer</p> |
| </div> |
| </div> |
| </aside> |
| |
| <!-- Main Content --> |
| <div id="content"> |
| <header class="bg-gray-800 text-white p-4"> |
| <div class="flex items-center"> |
| <button class="menu-toggle" id="menu-toggle"> |
| <i data-feather="menu"></i> |
| </button> |
| <div class="ml-4 font-bold text-xl">Jmotors</div> |
| </div> |
| <nav class="flex items-center space-x-6"> |
| <a href="transfer.php" class="hover:text-yellow-300">Transfer</a> |
| <a href="loan.php" class="hover:text-yellow-300">Loans</a> |
| <a href="daily-product.php" class="hover:text-yellow-300">New Product</a> |
| <div class="w-9 h-9 rounded-full bg-gradient-to-r from-yellow-300 to-orange-400 flex items-center justify-center font-bold"><?php echo substr($username, 0, 1); ?></div> |
| </nav> |
| </header> |
| |
| <main class="p-4"> |
| <?php if (isset($message)): ?> |
| <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4"> |
| <?php echo $message; ?> |
| </div> |
| <?php endif; ?> |
| |
| <?php if (isset($error)): ?> |
| <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4"> |
| <?php echo $error; ?> |
| </div> |
| <?php endif; ?> |
| |
| <?php if (isset($uploadError)): ?> |
| <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4"> |
| <?php echo $uploadError; ?> |
| </div> |
| <?php endif; ?> |
| |
| <div class="banner"> |
| <div class="title">🎉 Tuesday Giveaway Cashback! 🎄 Only at Jmotors</div> |
| <p>Upload marketing content and earn <strong>KES 50-85 per file</strong> based on quality and type!</p> |
| <div class="footer">📦 Fast payouts via M-Pesa • Powered by Jmotors</div> |
| </div> |
| |
| <div class="card mt-6"> |
| <div class="flex items-center gap-3 mb-6"> |
| <div class="w-11 h-11 rounded-lg bg-gray-800 bg-opacity-30 flex items-center justify-center text-2xl">📤</div> |
| <div> |
| <h3 class="text-2xl font-bold">Meta Uploads</h3> |
| <small class="text-gray-300">Upload content for rewards</small> |
| </div> |
| </div> |
| |
| <form id="upload-form" method="POST" enctype="multipart/form-data"> |
| <div class="upload-area" id="upload-area"> |
| <i data-feather="upload" class="text-4xl mx-auto text-gray-300"></i> |
| <h4 class="my-3 font-bold">Drag & Drop files here</h4> |
| <p class="text-gray-400 mb-4">or click to browse files</p> |
| <input type="file" id="file-input" name="uploaded_files[]" class="hidden" multiple accept="image/jpeg,image/png,video/mp4,application/pdf" <?php echo !$uploadDirCreated ? 'disabled' : ''; ?>> |
| <button type="button" class="btn" onclick="document.getElementById('file-input').click()" <?php echo !$uploadDirCreated ? 'disabled' : ''; ?>> |
| <?php echo $uploadDirCreated ? 'Select Files' : 'Uploads Disabled - Contact Admin'; ?> |
| </button> |
| </div> |
| </form> |
| |
| <div class="mt-6"> |
| <h4 class="font-bold mb-3">Upload Instructions</h4> |
| <ul class="list-disc pl-5 text-gray-300 space-y-2"> |
| <li>Upload at least 5 high-quality marketing content daily</li> |
| <li>Files should be in JPEG, PNG, MP4, or PDF format</li> |
| <li>Minimum resolution of 1280x720 for images/videos</li> |
| <li>Maximum file size: 50MB per file</li> |
| <li>Content must be original or properly licensed</li> |
| <li>Earn KES 50-85 per file based on type and quality</li> |
| </ul> |
| </div> |
| </div> |
| |
| <div class="card mt-6"> |
| <div class="flex justify-between items-center mb-4"> |
| <h3 class="text-xl font-bold">Today's Uploads (<?php echo $approvedUploads; ?>/5)</h3> |
| <div class="text-sm text-yellow-400">KES <?php echo number_format($todaysEarnings, 2); ?> earned</div> |
| </div> |
| |
| <div id="uploads-list"> |
| <?php if (empty($todaysUploads)): ?> |
| <div class="text-center py-8"> |
| <i data-feather="folder" class="mx-auto text-gray-400 text-4xl"></i> |
| <p class="mt-2 text-gray-400">No uploads today</p> |
| </div> |
| <?php else: ?> |
| <?php foreach ($todaysUploads as $upload): ?> |
| <div class="upload-item"> |
| <div class="flex items-center gap-3"> |
| <i data-feather="<?php echo getFileIcon($upload['file_type']); ?>" class="text-gray-300"></i> |
| <div> |
| <div><?php echo htmlspecialchars($upload['file_name']); ?></div> |
| <div class="text-xs text-gray-400"> |
| <?php echo formatFileSize($upload['file_size']); ?> • |
| <?php echo date('H:i', strtotime($upload['created_at'])); ?> |
| </div> |
| </div> |
| </div> |
| <div class="text-<?php echo $upload['status'] === 'approved' ? 'green' : 'yellow'; ?>-400 text-sm"> |
| KES <?php echo number_format($upload['reward_amount'], 2); ?> |
| </div> |
| </div> |
| <?php endforeach; ?> |
| <?php endif; ?> |
| </div> |
| </div> |
| </main> |
| |
| <script> |
| feather.replace(); |
| |
| document.addEventListener('DOMContentLoaded', function() { |
| const toggleBtn = document.getElementById('menu-toggle'); |
| const sidebar = document.getElementById('sidebar'); |
| const content = document.getElementById('content'); |
| const uploadForm = document.getElementById('upload-form'); |
| const fileInput = document.getElementById('file-input'); |
| const uploadArea = document.getElementById('upload-area'); |
| |
| toggleBtn.addEventListener('click', function() { |
| sidebar.classList.toggle('active'); |
| content.classList.toggle('active'); |
| }); |
| |
| |
| <?php if ($uploadDirCreated): ?> |
| |
| fileInput.addEventListener('change', function(e) { |
| if (this.files.length > 0) { |
| uploadForm.submit(); |
| } |
| }); |
| |
| |
| ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { |
| uploadArea.addEventListener(eventName, preventDefaults, false); |
| }); |
| |
| function preventDefaults(e) { |
| e.preventDefault(); |
| e.stopPropagation(); |
| } |
| |
| ['dragenter', 'dragover'].forEach(eventName => { |
| uploadArea.addEventListener(eventName, highlight, false); |
| }); |
| |
| ['dragleave', 'drop'].forEach(eventName => { |
| uploadArea.addEventListener(eventName, unhighlight, false); |
| }); |
| |
| function highlight() { |
| uploadArea.classList.add('border-yellow-400'); |
| uploadArea.style.backgroundColor = 'rgba(255,255,255,0.05)'; |
| } |
| |
| function unhighlight() { |
| uploadArea.classList.remove('border-yellow-400'); |
| uploadArea.style.backgroundColor = ''; |
| } |
| |
| uploadArea.addEventListener('drop', function(e) { |
| const dt = e.dataTransfer; |
| const files = dt.files; |
| fileInput.files = files; |
| |
| if (files.length > 0) { |
| uploadForm.submit(); |
| } |
| }); |
| <?php else: ?> |
| |
| uploadArea.style.cursor = 'not-allowed'; |
| uploadArea.style.opacity = '0.7'; |
| <?php endif; ?> |
| }); |
| |
| function getFileIcon(type) { |
| if(type.startsWith('image/')) return 'image'; |
| if(type.startsWith('video/')) return 'video'; |
| if(type === 'application/pdf') return 'file-text'; |
| return 'file'; |
| } |
| |
| function formatFileSize(bytes) { |
| if(bytes === 0) return '0 Bytes'; |
| const k = 1024; |
| const sizes = ['Bytes', 'KB', 'MB', 'GB']; |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; |
| } |
| </script> |
| </body> |
| </html> |