forked from projects/file-explorer
34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Forms\UploadFileForm;
|
|
use App\Service\FileSystemService;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class HomeController extends AbstractController
|
|
{
|
|
#[Route(
|
|
path: '/files/{dirs?}',
|
|
name: 'app_home',
|
|
requirements: ['dirs' => '.+'],
|
|
defaults: ['dirs' => ''],
|
|
methods: [Request::METHOD_GET]
|
|
)]
|
|
public function __invoke(FileSystemService $fileSystemService, string $dirs): Response
|
|
{
|
|
if ($fileSystemService->isFile(substr_replace($dirs, '', -1))) {
|
|
return $this->render('file.html.twig', [
|
|
'file' => $fileSystemService->getFile((string) substr_replace($dirs, '', -1)),
|
|
]);
|
|
}
|
|
|
|
return $this->render('home.html.twig', [
|
|
'content' => $fileSystemService->getDirs($dirs),
|
|
'fileForm' => $this->createForm(UploadFileForm::class),
|
|
]);
|
|
}
|
|
} |