From c45b4980882da0699c3d895cc7582b7604f46ab0 Mon Sep 17 00:00:00 2001 From: "Alex. Plokhikh" <a.plohih@iqdev.digital> Date: Wed, 17 Apr 2024 11:04:14 +0500 Subject: [PATCH] chenge login to read file from req --- src/Controller/ReadFileLineByLineController.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Controller/ReadFileLineByLineController.php b/src/Controller/ReadFileLineByLineController.php index d63b261..c6d0f03 100644 --- a/src/Controller/ReadFileLineByLineController.php +++ b/src/Controller/ReadFileLineByLineController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Actions\ReadFileLineByLineAction; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -15,20 +16,21 @@ class ReadFileLineByLineController extends AbstractController * * @param string $filePath путь до файла * @return Response */ - #[Route('/readbyline/{filePath}', name: 'app_read_file_line_by_line')] + #[Route('/readbyline', name: 'app_read_file_line_by_line', methods: ['POST'])] public function index( - string $filePath, + Request $request, ReadFileLineByLineAction $action ) : Response { - $file = ""; + $file = $request->files->get('File'); + $content = ""; try{ - foreach ($action->act($filePath) as $line) { - $file .= $line; + foreach ($action->act($file->getRealPath()) as $line) { + $content .= $line; } } catch (\Exception $exception) { return new Response($exception->getMessage(), Response::HTTP_NOT_FOUND); } - return new Response($file, Response::HTTP_OK); + return new Response($content); } } -- GitLab