Files
deskhub/DeskHub-Webseite/staff/upload_signature_image.php
T
2026-10-16 19:12:24 +00:00

57 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/../includes/bootstrap.php';
require_staff_login();
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['error' => 'Nur POST erlaubt.']);
exit;
}
verify_csrf();
if (empty($_FILES['image'])) {
http_response_code(422);
echo json_encode(['error' => 'Bitte eine Bilddatei auswählen.']);
exit;
}
$file = $_FILES['image'];
$allowedImageExts = array_values(array_intersect(get_allowed_extensions(), ['png', 'jpg', 'jpeg', 'gif']));
$ext = strtolower(pathinfo($file['name'] ?? '', PATHINFO_EXTENSION));
if ($file['error'] !== UPLOAD_ERR_OK) {
http_response_code(422);
echo json_encode(['error' => 'Der Upload ist fehlgeschlagen.']);
exit;
}
if (!in_array($ext, $allowedImageExts, true)) {
http_response_code(422);
echo json_encode(['error' => 'Nur Bilder erlaubt (' . implode(', ', array_map('strtoupper', $allowedImageExts)) . ').']);
exit;
}
if ($file['size'] > 5 * 1024 * 1024) {
http_response_code(422);
echo json_encode(['error' => 'Die Datei ist zu groß (max. 5 MB).']);
exit;
}
$result = handle_ticket_upload($file);
if (isset($result['error'])) {
http_response_code(422);
echo json_encode(['error' => $result['error']]);
exit;
}
$staff = current_staff();
audit_log($staff['id'], "Bild hochgeladen: {$result['stored_name']}");
// verify_csrf() hat den Session-Token bereits rotiert – der neue Wert muss zurück an die Seite,
// sonst schlägt das nachfolgende Absenden des umgebenden Formulars (z.B. Signatur speichern) fehl.
echo json_encode([
'url' => base_url() . '/uploads/' . $result['stored_name'],
'csrfToken' => csrf_token(),
]);