aboutsummaryrefslogtreecommitdiff
path: root/src/controller/FileUploadController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/FileUploadController.php')
-rw-r--r--src/controller/FileUploadController.php18
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
4declare(strict_types=1); 4declare(strict_types=1);
5 5
6use Symfony\Component\HttpFoundation\JsonResponse;
7
6class FileUploadController 8class 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