From ae217a6e4b0c29346381e2a410fd7810cb33ce3f Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 10 Jun 2026 20:56:25 +0200 Subject: =?UTF-8?q?Tous=20les=20contr=C3=B4leurs=20retournent=20une=20Resp?= =?UTF-8?q?onse!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/FileUploadController.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/controller/FileUploadController.php') diff --git a/src/controller/FileUploadController.php b/src/controller/FileUploadController.php index f53f5c2..3cd5e6b 100644 --- a/src/controller/FileUploadController.php +++ b/src/controller/FileUploadController.php @@ -3,9 +3,11 @@ declare(strict_types=1); +use Symfony\Component\HttpFoundation\JsonResponse; + class FileUploadController { - static public function checkFileDownload(array $file): bool + static private function checkFileDownload(array $file): bool { $extensions_white_list = ['pdf', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']; // = extensions_white_list côté javascript $mime_type_white_list = ['application/pdf', 'application/rtf', 'text/rtf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.presentation']; @@ -32,7 +34,7 @@ class FileUploadController return in_array($real_type, $mime_type_white_list, true); } - static public function fileUploadTinyMce(): void + static public function fileUploadTinyMce(): JsonResponse { if(isset($_FILES['file'])){ $dest = 'user_data/media/'; @@ -46,22 +48,18 @@ class FileUploadController if(self::checkFileDownload($_FILES['file'])){ if(move_uploaded_file($_FILES['file']['tmp_name'], $file_path)){ - echo json_encode(['location' => $file_path]); + return new JsonResponse(['location' => $file_path]); } else{ - http_response_code(500); - echo json_encode(['message' => 'Erreur enregistrement du fichier.']); + return new JsonResponse(['message' => 'Erreur enregistrement du fichier.'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 } } else{ - http_response_code(400); - echo json_encode(['message' => 'Erreur 400: fichier non valide.']); + return new JsonResponse(['message' => 'Erreur 400: fichier non valide.'], JsonResponse::HTTP_BAD_REQUEST); // code 400 } } else{ - http_response_code(400); - echo json_encode(['message' => 'Erreur 400: Bad Request']); + return new JsonResponse(['message' => 'Erreur 400: Bad Request'], JsonResponse::HTTP_BAD_REQUEST); // code 400 } - die; } } \ No newline at end of file -- cgit v1.2.3