diff options
| author | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
| commit | ae217a6e4b0c29346381e2a410fd7810cb33ce3f (patch) | |
| tree | 206f604c9297deabf78bb33f31a1e6b9303d2258 /src/controller/FileUploadController.php | |
| parent | 99d2616a08c98e7067cdb12f0bcbd4ac0cffaeb0 (diff) | |
| download | cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.gz cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.bz2 cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.zip | |
Tous les contrôleurs retournent une Response!
Diffstat (limited to 'src/controller/FileUploadController.php')
| -rw-r--r-- | src/controller/FileUploadController.php | 18 |
1 files changed, 8 insertions, 10 deletions
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 @@ | |||
| 3 | 3 | ||
| 4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
| 5 | 5 | ||
| 6 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
| 7 | |||
| 6 | class FileUploadController | 8 | class FileUploadController |
| 7 | { | 9 | { |
| 8 | static public function checkFileDownload(array $file): bool | 10 | static private function checkFileDownload(array $file): bool |
| 9 | { | 11 | { |
| 10 | $extensions_white_list = ['pdf', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']; // = extensions_white_list côté javascript | 12 | $extensions_white_list = ['pdf', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp']; // = extensions_white_list côté javascript |
| 11 | $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']; | 13 | $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 | |||
| 32 | return in_array($real_type, $mime_type_white_list, true); | 34 | return in_array($real_type, $mime_type_white_list, true); |
| 33 | } | 35 | } |
| 34 | 36 | ||
| 35 | static public function fileUploadTinyMce(): void | 37 | static public function fileUploadTinyMce(): JsonResponse |
| 36 | { | 38 | { |
| 37 | if(isset($_FILES['file'])){ | 39 | if(isset($_FILES['file'])){ |
| 38 | $dest = 'user_data/media/'; | 40 | $dest = 'user_data/media/'; |
| @@ -46,22 +48,18 @@ class FileUploadController | |||
| 46 | 48 | ||
| 47 | if(self::checkFileDownload($_FILES['file'])){ | 49 | if(self::checkFileDownload($_FILES['file'])){ |
| 48 | if(move_uploaded_file($_FILES['file']['tmp_name'], $file_path)){ | 50 | if(move_uploaded_file($_FILES['file']['tmp_name'], $file_path)){ |
| 49 | echo json_encode(['location' => $file_path]); | 51 | return new JsonResponse(['location' => $file_path]); |
| 50 | } | 52 | } |
| 51 | else{ | 53 | else{ |
| 52 | http_response_code(500); | 54 | return new JsonResponse(['message' => 'Erreur enregistrement du fichier.'], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 |
| 53 | echo json_encode(['message' => 'Erreur enregistrement du fichier.']); | ||
| 54 | } | 55 | } |
| 55 | } | 56 | } |
| 56 | else{ | 57 | else{ |
| 57 | http_response_code(400); | 58 | return new JsonResponse(['message' => 'Erreur 400: fichier non valide.'], JsonResponse::HTTP_BAD_REQUEST); // code 400 |
| 58 | echo json_encode(['message' => 'Erreur 400: fichier non valide.']); | ||
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | else{ | 61 | else{ |
| 62 | http_response_code(400); | 62 | return new JsonResponse(['message' => 'Erreur 400: Bad Request'], JsonResponse::HTTP_BAD_REQUEST); // code 400 |
| 63 | echo json_encode(['message' => 'Erreur 400: Bad Request']); | ||
| 64 | } | 63 | } |
| 65 | die; | ||
| 66 | } | 64 | } |
| 67 | } \ No newline at end of file | 65 | } \ No newline at end of file |
