From 327e382694573b31f7a25d92eb8ffc696d1c38b7 Mon Sep 17 00:00:00 2001 From: afornerot Date: Tue, 29 Jul 2025 22:20:51 +0200 Subject: [PATCH] svg --- config/packages/oneup_uploader.yaml | 4 +- src/Controller/FileController.php | 39 ++++++++- templates/file/browse.html.twig | 121 ++++++++++++++-------------- templates/file/upload.html.twig | 45 +++++++++++ 4 files changed, 147 insertions(+), 62 deletions(-) create mode 100644 templates/file/upload.html.twig diff --git a/config/packages/oneup_uploader.yaml b/config/packages/oneup_uploader.yaml index e8c97c1..fc316f6 100644 --- a/config/packages/oneup_uploader.yaml +++ b/config/packages/oneup_uploader.yaml @@ -3,4 +3,6 @@ oneup_uploader: avatar: frontend: dropzone logo: - frontend: dropzone \ No newline at end of file + frontend: dropzone + file: + frontend: dropzone \ No newline at end of file diff --git a/src/Controller/FileController.php b/src/Controller/FileController.php index d3c8d85..4e7c0a4 100644 --- a/src/Controller/FileController.php +++ b/src/Controller/FileController.php @@ -3,7 +3,9 @@ namespace App\Controller; use App\Service\FileService; +use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -45,11 +47,44 @@ class FileController extends AbstractController } } - #[Route('/user/file/{domain}/{id}/uploadmodal', name: 'app_files_uploadmodal', methods: ['GET'])] - public function upload(string $domain, int $id, Request $request): Response + #[Route('/user/uploadmodal/{domain}/{id}', name: 'app_files_uploadmodal', methods: ['GET'])] + public function uploadmodal(string $domain, int $id, Request $request): Response { $relativePath = $request->query->get('path', ''); + return $this->render('file\upload.html.twig', [ + 'useheader' => false, + 'usemenu' => false, + 'usesidebar' => false, + 'endpoint' => 'file', + 'domain' => $domain, + 'id' => $id, + 'path' => $relativePath, + ]); + } + + #[Route('/user/uploadfile', name: 'app_files_uploadfile', methods: ['POST'])] + public function upload(Request $request): Response|ResponseInterface + { + /** @var UploadedFile $file */ + $file = $request->files->get('file'); + $domain = $request->query->get('domain'); + $id = $request->query->get('id'); + $relativePath = $request->query->get('path', ''); + + if (!$file || !$domain || !$id) { + return new Response('Invalid parameters', 400); + } + + $baseDir = $this->getParameter('kernel.project_dir').'/uploads/'.$domain.'/'.$id.'/'.ltrim($relativePath, '/'); + + if (!is_dir($baseDir)) { + mkdir($baseDir, 0775, true); + } + + $originalName = $file->getClientOriginalName(); + $file->move($baseDir, $originalName); + return new JsonResponse(['success' => true]); } diff --git a/templates/file/browse.html.twig b/templates/file/browse.html.twig index 0e6d996..f6f6164 100644 --- a/templates/file/browse.html.twig +++ b/templates/file/browse.html.twig @@ -11,11 +11,7 @@ {% if editable %}
-
- - - -
+ Upload
{% endif %} @@ -50,72 +46,79 @@ + + diff --git a/templates/file/upload.html.twig b/templates/file/upload.html.twig new file mode 100644 index 0000000..2da499f --- /dev/null +++ b/templates/file/upload.html.twig @@ -0,0 +1,45 @@ +{% extends 'base.html.twig' %} + +{% block localstyle %} + +{% endblock %} + +{% block body %} + Annuler +
+{% endblock %} + +{% block localscript %} + +{% endblock %}