41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
require_once __DIR__ . '/common.php';
|
||
|
||
// Für Signatur-Bilder (Mitarbeiter/Abteilung). Jeder angemeldete Mitarbeiter darf
|
||
// eigene Bilder hochladen – die Rechteprüfung für die eigentliche Signatur passiert
|
||
// beim Speichern (staff_manage.php / departments.php), nicht hier.
|
||
api_require_method('POST');
|
||
$staff = api_require_staff();
|
||
|
||
if (empty($_FILES['image'])) {
|
||
api_error(422, 'FILE_REQUIRED', 'Bitte eine Bilddatei auswählen.');
|
||
}
|
||
|
||
$file = $_FILES['image'];
|
||
// Bewusst auf die vom Server ohnehin erlaubten Bild-Endungen beschränkt (siehe config.php /
|
||
// Einstellungen → Uploads), damit handle_ticket_upload() den Upload nicht widersprüchlich ablehnt.
|
||
$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) {
|
||
api_error(422, 'UPLOAD_FAILED', 'Der Upload ist fehlgeschlagen.');
|
||
}
|
||
if (!in_array($ext, $allowedImageExts, true)) {
|
||
api_error(422, 'INVALID_TYPE', 'Nur Bilder erlaubt (' . implode(', ', array_map('strtoupper', $allowedImageExts)) . ').');
|
||
}
|
||
if ($file['size'] > 5 * 1024 * 1024) {
|
||
api_error(422, 'FILE_TOO_LARGE', 'Die Datei ist zu groß (max. 5 MB).');
|
||
}
|
||
|
||
$result = handle_ticket_upload($file);
|
||
if (isset($result['error'])) {
|
||
api_error(422, 'UPLOAD_FAILED', $result['error']);
|
||
}
|
||
|
||
audit_log($staff['id'], "Bild hochgeladen: {$result['stored_name']} (Mobile App)");
|
||
|
||
api_json([
|
||
'url' => base_url() . '/uploads/' . $result['stored_name'],
|
||
]);
|