Skip to content
Snippets Groups Projects
Commit 31431e3c authored by Akex's avatar Akex Committed by Александр Плохих
Browse files

make controller

parent 295a6342
No related branches found
No related tags found
1 merge request!8make controller
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
hello World
</body>
</html>
\ No newline at end of file
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class ReadLogFileController extends AbstractController
{
/**
* Принимает путь до файла,
* проверяет, что файл существует и выводит пользователю весь контент файла
* (файл можешь создать любой)
*
* @param string $filePath путь до файла
* @return Response */
#[Route('/read/{filePath}', name: 'app_read_log_file', methods: ['GET'])]
public function index(string $filePath): Response
{
$fileSystem = new Filesystem();
if (!$fileSystem->exists($filePath)) {
return new Response('File not found', Response::HTTP_NOT_FOUND);
}
return new Response(file_get_contents($filePath), Response::HTTP_OK);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment