diff --git a/system/Files/File.php b/system/Files/File.php index 7773dbcf59fa..f82723ba6e7c 100644 --- a/system/Files/File.php +++ b/system/Files/File.php @@ -150,7 +150,9 @@ public function getMimeType(): string */ public function getRandomName(): string { - return time() . '_' . bin2hex(random_bytes(10)) . '.' . $this->getExtension(); + $extension = $this->getExtension(); + $extension = empty($extension) ? '' : '.' . $extension; + return time() . '_' . bin2hex(random_bytes(10)) . $extension; } //-------------------------------------------------------------------- @@ -203,6 +205,7 @@ public function getDestination(string $destination, string $delimiter = '_', int while (is_file($destination)) { $info = pathinfo($destination); + $extension = isset($info['extension']) ? '.' . $info['extension'] : ''; if (strpos($info['filename'], $delimiter) !== false) { $parts = explode($delimiter, $info['filename']); @@ -211,16 +214,16 @@ public function getDestination(string $destination, string $delimiter = '_', int $i = end($parts); array_pop($parts); array_push($parts, ++ $i); - $destination = $info['dirname'] . '/' . implode($delimiter, $parts) . '.' . $info['extension']; + $destination = $info['dirname'] . '/' . implode($delimiter, $parts) . $extension; } else { - $destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . '.' . $info['extension']; + $destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . $extension; } } else { - $destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . '.' . $info['extension']; + $destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . $extension; } } return $destination; diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index bd37a84c6ee5..81315a49e978 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -200,12 +200,12 @@ trusted version, use ``getExtension()`` instead:: $ext = $file->getClientExtension(); -**getClientType()** +**getClientMimeType()** Returns the mime type (mime type) of the file as provided by the client. This is NOT a trusted value. For a trusted -version, use ``getType()`` instead:: +version, use ``getMimeType()`` instead:: - $type = $file->getClientType(); + $type = $file->getClientMimeType(); echo $type; // image/png