T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/private_html/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/api/upload_profile_image.php
<?php
session_start();
header('Content-Type: application/json');

// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
    http_response_code(401);
    echo json_encode(['success' => false, 'error' => 'Authentication required']);
    exit;
}

// Include database configuration
require_once '../config/database.php';

try {
    $pdo = getDBConnection();
    if (!$pdo) {
        throw new Exception('Database connection failed');
    }

    // Check if file was uploaded
    if (!isset($_FILES['profile_image']) || $_FILES['profile_image']['error'] !== UPLOAD_ERR_OK) {
        throw new Exception('No image file uploaded or upload error occurred');
    }

    $file = $_FILES['profile_image'];
    
    // Validate file type
    $allowed_types = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'];
    if (!in_array($file['type'], $allowed_types)) {
        throw new Exception('Invalid file type. Only JPG, PNG, and GIF are allowed.');
    }

    // Validate file size (max 5MB)
    if ($file['size'] > 5 * 1024 * 1024) {
        throw new Exception('File too large. Maximum size is 5MB.');
    }

    // Create upload directory if it doesn't exist
    $upload_dir = '../uploads/profile_images/';
    if (!is_dir($upload_dir)) {
        mkdir($upload_dir, 0755, true);
    }

    // Generate unique filename
    $extension = pathinfo($file['name'], PATHINFO_EXTENSION);
    $filename = 'profile_' . $_SESSION['user_id'] . '_' . time() . '.' . $extension;
    $filepath = $upload_dir . $filename;

    // Move uploaded file
    if (!move_uploaded_file($file['tmp_name'], $filepath)) {
        throw new Exception('Failed to save uploaded file');
    }

    // Compress and optimize the image
    require_once '../utils/image_compression.php';
    $compression_result = compressProfileImage($filepath);
    
    if ($compression_result['success']) {
        // Update filename if format changed (e.g., PNG to JPEG)
        if (!empty($compression_result['format_changed']) && $compression_result['format_changed']) {
            $filename = basename($compression_result['filepath']);
        }
        error_log("Profile image compressed: " . ($compression_result['message'] ?? 'Success'));
    } else {
        error_log("Image compression warning: " . ($compression_result['error'] ?? 'Unknown error'));
        // Continue even if compression fails - original image is still usable
    }

    // Create web-accessible URL
    $image_url = '/uploads/profile_images/' . $filename;

    // Update user profile in database
    $stmt = $pdo->prepare("
        UPDATE users 
        SET profile_image = ? 
        WHERE id = ?
    ");
    $stmt->execute([$image_url, $_SESSION['user_id']]);

    // Also update user_profiles table if it exists
    $stmt = $pdo->prepare("
        INSERT INTO user_profiles (user_id, profile_image, created_at, updated_at) 
        VALUES (?, ?, NOW(), NOW())
        ON DUPLICATE KEY UPDATE 
            profile_image = ?, updated_at = NOW()
    ");
    $stmt->execute([$_SESSION['user_id'], $image_url, $image_url]);

    // Log the upload
    error_log("Profile image uploaded for user {$_SESSION['user_id']}: $image_url");

    echo json_encode([
        'success' => true,
        'message' => 'Profile image uploaded successfully',
        'data' => [
            'image_url' => $image_url,
            'filename' => $filename
        ]
    ]);

} catch (Exception $e) {
    error_log("Profile image upload error: " . $e->getMessage());
    http_response_code(500);
    echo json_encode([
        'success' => false,
        'error' => 'Failed to upload image: ' . $e->getMessage()
    ]);
}
?> 

CasperSecurity Mini