Fix: Profile picture upload issues and improved error handling

- account_settings.php: Show success message before reloading page (with 1.5s delay)
- upload_profile_picture.php: Reorder require statements for proper initialization, add file error code to error message
This commit is contained in:
twotalesanimation
2025-12-04 15:59:49 +02:00
parent 0c068eeb69
commit 59c1e37d5c
4 changed files with 13 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -175,11 +175,11 @@ $user = $result->fetch_assoc();
}
if (response.status === 'success') {
// Update the profile picture source with cache-busting query string
// Reload the current page
window.location.reload();
$('#responseMessage').html('<div class="alert alert-success">' + response.message + '</div>');
// Reload the current page after a short delay
setTimeout(function() {
window.location.reload();
}, 1500);
} else {
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
}

View File

@@ -1,9 +1,15 @@
<?php
session_start();
$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");
require_once($rootPath . "/src/config/env.php");
// Check database connection
if (!isset($conn) || $conn === null) {
die(json_encode(['status' => 'error', 'message' => 'Database connection failed']));
}
$response = array('status' => 'error', 'message' => 'Something went wrong');
@@ -69,11 +75,11 @@ if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] !=
// Log the action
auditLog($user_id, 'PROFILE_PIC_UPLOAD', 'users', $user_id, ['filename' => $randomFilename]);
} else {
$response['message'] = 'Failed to update profile picture in the database';
$response['message'] = 'Failed to update profile picture in the database: ' . $stmt->error;
}
$stmt->close();
} else {
$response['message'] = 'Failed to move uploaded file.';
$response['message'] = 'Failed to move uploaded file. Error code: ' . $_FILES['profile_picture']['error'];
}
} else {
$response['message'] = 'No file uploaded or file error.';