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) {