From 719c42d7a4774e26f4b3669f608c3754d7d9f1b1 Mon Sep 17 00:00:00 2001 From: zorn-v Date: Thu, 21 Mar 2024 06:44:39 +1000 Subject: [PATCH 1/4] Fix upload file to subdir --- src/Form/Type/FileUploadType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Type/FileUploadType.php b/src/Form/Type/FileUploadType.php index e78d3bef1e..32dcff20f7 100644 --- a/src/Form/Type/FileUploadType.php +++ b/src/Form/Type/FileUploadType.php @@ -77,7 +77,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): public function configureOptions(OptionsResolver $resolver): void { $uploadNew = static function (UploadedFile $file, string $uploadDir, string $fileName) { - $file->move($uploadDir, $fileName); + $file->move($uploadDir.'/'.dirname($filename), $fileName); }; $uploadDelete = static function (File $file) { From bcb96dbd5de1f16344897a5591749e1bae4f4193 Mon Sep 17 00:00:00 2001 From: zorn-v Date: Thu, 21 Mar 2024 07:05:32 +1000 Subject: [PATCH 2/4] Fix typo --- src/Form/Type/FileUploadType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Type/FileUploadType.php b/src/Form/Type/FileUploadType.php index 32dcff20f7..4d450038b6 100644 --- a/src/Form/Type/FileUploadType.php +++ b/src/Form/Type/FileUploadType.php @@ -77,7 +77,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): public function configureOptions(OptionsResolver $resolver): void { $uploadNew = static function (UploadedFile $file, string $uploadDir, string $fileName) { - $file->move($uploadDir.'/'.dirname($filename), $fileName); + $file->move($uploadDir.'/'.dirname($fileName), $fileName); }; $uploadDelete = static function (File $file) { From 55514a209801f3c88a5d76a0275a80b75abe986c Mon Sep 17 00:00:00 2001 From: zorn Date: Thu, 21 Mar 2024 10:08:01 +1000 Subject: [PATCH 3/4] Fix reverse transform of file name --- src/Form/DataTransformer/StringToFileTransformer.php | 2 +- src/Form/Type/FileUploadType.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Form/DataTransformer/StringToFileTransformer.php b/src/Form/DataTransformer/StringToFileTransformer.php index 740d718aef..a922e0a3e1 100644 --- a/src/Form/DataTransformer/StringToFileTransformer.php +++ b/src/Form/DataTransformer/StringToFileTransformer.php @@ -97,7 +97,7 @@ private function doReverseTransform($value): ?string } if ($value instanceof File) { - return $value->getFilename(); + return str_replace($this->uploadDir, '', $value->getPathname()); } throw new TransformationFailedException('Expected an instance of File or null.'); diff --git a/src/Form/Type/FileUploadType.php b/src/Form/Type/FileUploadType.php index 4d450038b6..d7171b9d1a 100644 --- a/src/Form/Type/FileUploadType.php +++ b/src/Form/Type/FileUploadType.php @@ -77,7 +77,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): public function configureOptions(OptionsResolver $resolver): void { $uploadNew = static function (UploadedFile $file, string $uploadDir, string $fileName) { - $file->move($uploadDir.'/'.dirname($fileName), $fileName); + $file->move($uploadDir.'/'.\dirname($fileName), $fileName); }; $uploadDelete = static function (File $file) { From 642df52bac5f57279eed91ec2e9f14170dfd4a49 Mon Sep 17 00:00:00 2001 From: zorn-v Date: Thu, 21 Mar 2024 14:36:46 +1000 Subject: [PATCH 4/4] Remove extra slash --- src/Form/Type/FileUploadType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/Type/FileUploadType.php b/src/Form/Type/FileUploadType.php index d7171b9d1a..a5890380b8 100644 --- a/src/Form/Type/FileUploadType.php +++ b/src/Form/Type/FileUploadType.php @@ -77,7 +77,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): public function configureOptions(OptionsResolver $resolver): void { $uploadNew = static function (UploadedFile $file, string $uploadDir, string $fileName) { - $file->move($uploadDir.'/'.\dirname($fileName), $fileName); + $file->move($uploadDir.\dirname($fileName), $fileName); }; $uploadDelete = static function (File $file) {