appKernel = $appKernel; $this->minio = $minio; } public function ckupload($access, Request $request): Response { // Fichier temporaire uploadé $tmpfile = $request->files->get('upload'); $extention = $tmpfile->getClientOriginalExtension(); // Répertoire de Destination $fs = new Filesystem(); $rootdir = $this->getParameter('kernel.project_dir').'/var/tmp'; $fs->mkdir($rootdir.'/ckeditor'); // Fichier cible $targetName = uniqid().'.'.$extention; $targetFile = 'ckeditor/'.$targetName; $targetUrl = $this->generateUrl('app_minio_document', ['file' => 'ckeditor/'.$targetName]); // move_uploaded_file($tmpfile,$targetFile); $this->minio->upload($tmpfile, $targetFile, true); $output['uploaded'] = 1; $output['fileName'] = $targetName; $output['url'] = $targetUrl; return new Response(json_encode($output)); } public function logo(Request $request): Response { return $this->redirectToRoute('app_minio_image', ['file' => 'logo/'.$request->getSession()->get('logolight')]); } public function image(Request $request): Response { $file = $request->query->get('file'); switch ($file) { case 'avatar/admin.jpg': case 'avatar/noavatar.png': case 'avatar/system.jpg': case 'header/header.jpg': case 'logo/logo.png': $file = 'medias/'.$file; $filePath = $file; $response = new BinaryFileResponse($filePath); $response->headers->set('Content-Type', mime_content_type($filePath)); return $response; break; default: // Icons ? if (0 === stripos($file, 'icon/icon_')) { $file = 'medias/'.$file; $filePath = $file; $response = new BinaryFileResponse($filePath); $response->headers->set('Content-Type', mime_content_type($filePath)); return $response; } // C'est une url = on affiche l'url elseif (0 === stripos($file, 'http')) { $filePath = $file; $content = file_get_contents($file); } // C'est du contenu dynamique on download depuis minio else { return new Response($this->minio->image($file, $file)); } break; } return new Response($content, 200, [ 'Content-Type' => mime_content_type($filePath), 'Cache-Control' => 'max-age='.(60 * 60 * 24 * 7), 'Expires' => gmdate(DATE_RFC1123, time() + 60 * 60 * 24 * 365), ]); } public function document(Request $request) { $file = $request->query->get('file'); $filePath = $this->minio->download($file, $file, true); $content = file_get_contents($filePath); return new Response($content, 200, [ 'Content-Type' => mime_content_type($filePath), 'Cache-Control' => 'max-age='.(60 * 60 * 24 * 7), 'Expires' => gmdate(DATE_RFC1123, time() + 60 * 60 * 24 * 365), ]); } }