setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdo; } catch (PDOException $e) { die("Database connection failed: " . $e->getMessage()); } } // Correct absolute upload directory - using a directory that's more likely to have write permissions $uploadDir = __DIR__ . '/uploads/'; // Ensure uploads directory exists with correct permissions $uploadDirCreated = false; if (!is_dir($uploadDir)) { if (!mkdir($uploadDir, 0755, true)) { // Try an alternative location if the first one fails $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; } // Check if directory is writable if ($uploadDirCreated && !is_writable($uploadDir)) { if (!chmod($uploadDir, 0755)) { $uploadError = "❌ Upload directory is not writable. Please fix permissions for: " . $uploadDir; $uploadDirCreated = false; } } // Handle file upload $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]; // Allowed types & size $allowedTypes = ['image/jpeg', 'image/png', 'video/mp4', 'application/pdf']; $maxSize = 50 * 1024 * 1024; // 50 MB if (in_array($fileType, $allowedTypes) && $fileSize <= $maxSize) { // Unique filename $extension = pathinfo($name, PATHINFO_EXTENSION); $filename = uniqid("file_", true) . '.' . $extension; $filePath = $uploadDir . $filename; if (move_uploaded_file($tmpName, $filePath)) { // Calculate reward based on file type $reward = calculateReward($fileType, $fileSize); // Save to database if (saveUploadToDB($userId, $name, $fileType, $fileSize, $filePath, $reward)) { $uploadResults[] = [ 'success' => true, 'name' => $name, 'reward' => $reward ]; // Update user balance 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] ]; } } // Refresh user session data refreshUserSession($userId, $uploadResults); } // Calculate reward based on file type and size 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; } // Add bonus for larger files if ($fileSize > 10 * 1024 * 1024) { // Over 10MB $baseReward += 10; } return $baseReward; } // Save upload to database 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; } } // Update user balance function updateUserBalance($userId, $reward) { try { $pdo = getDBConnection(); // Update balance $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 to refresh user session data 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; // Update the global variables used in the page global $balance, $rewards, $meta_earnings; $balance = $_SESSION['balance']; $rewards = $_SESSION['rewards']; $meta_earnings = $_SESSION['meta_earnings']; } } // Get today's uploads 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 []; } } // Get today's upload stats 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]; } } // Display upload results if any 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."; } } // Get today's uploads and stats $todaysUploads = getTodaysUploads($userId); $uploadStats = getTodaysUploadStats($userId); $totalUploads = $uploadStats['total_uploads'] ?? 0; $approvedUploads = $uploadStats['approved_uploads'] ?? 0; $todaysEarnings = $uploadStats['total_earnings'] ?? 0; // Helper functions 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]; } ?> Japanese Motors — Uploads
Jmotors
📤

Meta Uploads

Upload content for rewards

Drag & Drop files here

or click to browse files

>

Upload Instructions

  • Upload at least 5 high-quality marketing content daily
  • Files should be in JPEG, PNG, MP4, or PDF format
  • Minimum resolution of 1280x720 for images/videos
  • Maximum file size: 50MB per file
  • Content must be original or properly licensed
  • Earn KES 50-85 per file based on type and quality

Today's Uploads (/5)

KES earned

No uploads today

KES