From f11e062761c5655e0734d7ae8552f4219a5aab86 Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Wed, 21 Aug 2024 13:38:55 +1200 Subject: [PATCH] ENH ensure file title constructed from original filename --- src/File.php | 4 ++-- src/Upload.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/File.php b/src/File.php index 722b1ca0..0e033599 100644 --- a/src/File.php +++ b/src/File.php @@ -728,10 +728,10 @@ protected function onBeforeWrite() // Update title if (!$title) { // Generate a readable title, dashes and underscores replaced by whitespace, - // and any file extensions removed. + // and any file extensions removed, from the file original name $this->setField( 'Title', - str_replace(['-','_'], ' ', preg_replace('/\.[^.]+$/', '', $name ?? '') ?? '') + str_replace(['-','_'], ' ', (string) preg_replace('/\.[^.]+$/', '', (string) $this->getField('OriginalName'))) ); } diff --git a/src/Upload.php b/src/Upload.php index 78719d2c..a9e6c834 100644 --- a/src/Upload.php +++ b/src/Upload.php @@ -199,6 +199,9 @@ public function loadIntoFile($tmpFile, $file = null, $folderPath = false) } $filename = $this->resolveExistingFile($filename); + // Store teh actual file name before any transformation from getValidFilename + $this->file->setField('OriginalName', $tmpFile['name']); + // Save changes to underlying record (if it's a DataObject) $this->storeTempFile($tmpFile, $filename, $this->file); if ($this->file instanceof DataObject) {