Commit f7ec08af authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

fix

parent b594f6ba
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -96,23 +96,21 @@ class HomeController extends AbstractController
    }

    #[Route('/readLogFile', name: 'readLogFile')]
    public function readLogFile(Request $request, FileUploader $fileUploader): Response
    public function readLogFile(Request $request): Response
    {
        $file = $request->files->get('file');
        $fileName = $fileUploader->upload($file);
        $text = $this->functions->readLogFile($fileName);
        $text = $this->functions->readLogFile($file);
        $response = new JsonResponse($text);
        $response->setEncodingOptions(JSON_UNESCAPED_UNICODE);
        return $response;
    }

    #[Route('/readFileLineByLine', name: 'readFileLineByLine')]
    public function readFileLineByLine(Request $request, FileUploader $fileUploader): Response // text.txt
    public function readFileLineByLine(Request $request): Response // text.txt
    {
        $file = $request->files->get('file');
        $fileName = $fileUploader->upload($file);
        $text = "";
        foreach ($this->functions->readFileLineByLine($fileName) as $line) {
        foreach ($this->functions->readFileLineByLine($file) as $line) {
            $text .= $line;
        }
        $response = new JsonResponse($text);

src/Service/FileUploader.php

deleted100644 → 0
+0 −33
Original line number Diff line number Diff line
<?php

namespace App\Service;

use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class FileUploader
{
    private $targetDirectory;

    public function __construct($targetDirectory)
    {
        $this->targetDirectory = $targetDirectory;
    }

    public function upload(UploadedFile $file)
    {
        $fileName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) .'.'. $file->guessExtension();
        try {
            $file->move($this->getTargetDirectory(), $fileName);
        } catch (FileException $e) {
            throw new FileException($e->getMessage());
        }

        return $this->getTargetDirectory() . $fileName;
    }

    public function getTargetDirectory()
    {
        return $this->targetDirectory;
    }
}
 No newline at end of file