diff --git a/src/Controller/ReadFileLineByLineController.php b/src/Controller/ReadFileLineByLineController.php index d63b261239944d2e4076b68d647a9c315b320242..c6d0f0398a031505d844e51636a858ad469b7bc7 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); } }