add site to view and upload files

Reviewed-on: sites/file-explorer#4
This commit is contained in:
2024-12-05 09:42:25 +00:00
parent 1ec2ed1d00
commit bf226d7e3f
31 changed files with 2178 additions and 6 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace App\Service;
use App\Objects\DirContent;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class FileSystemService
{
public function __construct(
#[Autowire(env: 'DATA_DIR')]
private readonly string $dir,
private readonly Filesystem $filesystem,
) {
}
/**
* @return DirContent[]
*/
public function getDirs(): array
{
$finder = new Finder();
$finder->in($this->dir);
$contents = [];
foreach ($finder->depth(0) as $content) {
$contents[] = DirContent::make($content);
}
return $contents;
}
/**
* @param UploadedFile[] $files
*/
public function uploadFile(array $files): void
{
foreach ($files as $file) {
$this->filesystem->dumpFile($this->dir . '/' . $file->getClientOriginalName(), $file->getContent());
}
}
}