feat: organize uploads into subfolders

This commit is contained in:
Björn Fromme
2025-03-19 08:22:53 +01:00
parent 4d771817d8
commit 374e01cf1d
3 changed files with 11 additions and 4 deletions
+4 -1
View File
@@ -10,6 +10,7 @@ use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\RequestStack;
use function Symfony\Component\String\s;
class UploadHandler
{
@@ -119,7 +120,9 @@ class UploadHandler
public function getUploadFilepath(Upload $upload): string
{
return sprintf('%s/uploads/%s/%s', $this->projectDir, $upload->getType(), $upload->getFilename());
$folder = substr($upload->getFilename(), 0, 1);
return sprintf('%s/uploads/%s/%s/%s', $this->projectDir, $upload->getType(), $folder, $upload->getFilename());
}
public function getTempUploadFilepath(UploadDto $uploadDto, string $uploadSessionId): string
+5 -2
View File
@@ -10,6 +10,9 @@ class UploadNamer implements NamerInterface
{
public function name(FileInterface $file): string
{
return sprintf('%s.%s', Uuid::v4(), strtolower($file->getExtension()));
$fileUuid = Uuid::v7();
$folder = substr($fileUuid, 0, 1);
return sprintf('%s/%s.%s', $folder, $fileUuid, strtolower($file->getExtension()));
}
}
}
@@ -5,6 +5,7 @@
{% block content %}
{{ form_start(form, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
<a href="{{ path('app_common_download', { 'uuid': document.uuid, 'inline': true }) }}"
target="_blank"
class="flex justify-between items-center pb-4"
title="Dokument öffnen">
<h2 class="font-bold text-lg">
@@ -24,4 +25,4 @@
</button>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
{% endblock %}