Fix: Clean output buffer in upload_profile_picture.php to prevent HTML in JSON response

- Move header() call to before any includes that might output
- Start output buffering at the beginning
- Clean output buffer before sending JSON response
This commit is contained in:
twotalesanimation
2025-12-04 16:05:44 +02:00
parent 79e292dc7c
commit 716de2f0e9
3 changed files with 7 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

View File

@@ -1,14 +1,16 @@
<?php
ob_start(); // Start output buffering
session_start();
// Set JSON response header BEFORE any other output
header('Content-Type: application/json');
$rootPath = dirname(dirname(__DIR__));
require_once($rootPath . "/src/config/env.php");
require_once($rootPath . "/src/config/session.php");
include_once($rootPath . '/src/config/connection.php');
require_once($rootPath . "/src/config/functions.php");
// Set JSON response header
header('Content-Type: application/json');
// Check database connection
if (!isset($conn) || $conn === null) {
die(json_encode(['status' => 'error', 'message' => 'Database connection failed']));
@@ -88,6 +90,8 @@ if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] !=
$response['message'] = 'No file uploaded or file error.';
}
// Clean output buffer and send only JSON
ob_end_clean();
echo json_encode($response);
?>