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:
BIN
assets/images/pp/424b31c09e1543a922deb690bfbb57c8.png
Normal file
BIN
assets/images/pp/424b31c09e1543a922deb690bfbb57c8.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 291 KiB |
BIN
assets/images/pp/b8d7fa81c1ab3e67dc86441b09d927cd.jpg
Normal file
BIN
assets/images/pp/b8d7fa81c1ab3e67dc86441b09d927cd.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
@@ -1,14 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
ob_start(); // Start output buffering
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
|
// Set JSON response header BEFORE any other output
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
$rootPath = dirname(dirname(__DIR__));
|
$rootPath = dirname(dirname(__DIR__));
|
||||||
require_once($rootPath . "/src/config/env.php");
|
require_once($rootPath . "/src/config/env.php");
|
||||||
require_once($rootPath . "/src/config/session.php");
|
require_once($rootPath . "/src/config/session.php");
|
||||||
include_once($rootPath . '/src/config/connection.php');
|
include_once($rootPath . '/src/config/connection.php');
|
||||||
require_once($rootPath . "/src/config/functions.php");
|
require_once($rootPath . "/src/config/functions.php");
|
||||||
|
|
||||||
// Set JSON response header
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
|
|
||||||
// Check database connection
|
// Check database connection
|
||||||
if (!isset($conn) || $conn === null) {
|
if (!isset($conn) || $conn === null) {
|
||||||
die(json_encode(['status' => 'error', 'message' => 'Database connection failed']));
|
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.';
|
$response['message'] = 'No file uploaded or file error.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean output buffer and send only JSON
|
||||||
|
ob_end_clean();
|
||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user