Repository: LycheeOrg/Lychee (language: php)

Issue:
File-Suffixes duplicated in Downloaded Album
### Discussed in https://github.com/LycheeOrg/Lychee/discussions/2440

<div type='discussions-op-text'>

<sup>Originally posted by **fmaack** May 20, 2024</sup>
### Lychee version

v5.3

### Which PHP version are you using?

PHP 8.3

### Detailed description of the problem

I am using the "Download Album"-Feature which creates a zip-file containing all the images.

The filenames of the images inside the zip-file contains the filetype two times.

### Steps to reproduce the issue

1. upload an image IMG_123.jpeg into an album.
2. use the "Download Album" Button.
3. unpack the zip-File.

Result: The downloaded filename ist IMG_123.jpeg.jpeg.

### Diagnostics [REQUIRED]

_No response_

### Browser & System [REQUIRED]

_No response_

### Please confirm (incomplete submissions will not be addressed)

- [X] I have provided easy and step-by-step instructions to reproduce the bug.
- [X] I understand my bug report will be removed if I haven't met the criteria above.</div>


Discussion / hints:
I wanted to report this bug as well. I might have a few additional things to add, however:
- This also happens if you download a single image in the original size.
- This does not happen with images, that have been downsized during the import.
- This only happens, when the image was **uploaded using the new, v5 layout**.
  - When uploading the image using the v5 layout, the full filename + extension is used as the images "title". The old layout did not save the extension in the title.
  - When uploading an image with the v5 and switching back to the old layout, the same issue arises with the extension being added twice when downloading the image uploaded with the v5 interface.

*Thus, I believe the issue lies with the full filename being saved during the upload, not with the download.*

<details> 
  <summary>My quick & dirty SQL fix</summary>
   
   Running a query, such as the following, will remove the extension from the title and result in the expected filename when downloading.

  The extension in the query will have to be adjusted to your use case. Be careful when using this query, as it may delete other information from the title than expected, as it only checks for the presence of ".jpg" (anywhere) in the title and removes the last 4 characters of such titles.

  **USE AT YOUR OWN RISK!**

  ```
  UPDATE photos SET title = SUBSTRING(title, 1, LENGTH(title) - 4) WHERE title LIKE '%.jpg';
  ```
</details>



Fix patch:
diff --git a/app/Actions/Album/Archive.php b/app/Actions/Album/Archive.php
index 1eb344d9e2a..6f5b7cb6c07 100644
--- a/app/Actions/Album/Archive.php
+++ b/app/Actions/Album/Archive.php
@@ -127,6 +127,7 @@ private static function createZipTitle(Collection $albums): string
 	private static function createValidTitle(string $title): string
 	{
 		$validTitle = str_replace(self::BAD_CHARS, '', $title);
+		$validTitle = pathinfo($validTitle, PATHINFO_FILENAME);
 
 		return $validTitle !== '' ? $validTitle : 'Untitled';
 	}
diff --git a/app/Actions/Photo/Archive.php b/app/Actions/Photo/Archive.php
index cad7e4c3567..ee8a46b769d 100644
--- a/app/Actions/Photo/Archive.php
+++ b/app/Actions/Photo/Archive.php
@@ -282,6 +282,7 @@ protected function extractFileInfo(Photo $photo, DownloadVariantType $downloadVa
 	{
 		$validFilename = str_replace(self::BAD_CHARS, '', $photo->title);
 		$baseFilename = $validFilename !== '' ? $validFilename : 'Untitled';
+		$baseFilename = pathinfo($baseFilename, PATHINFO_FILENAME);
 
 		if ($downloadVariant === DownloadVariantType::LIVEPHOTOVIDEO) {
 			$disk = $photo->size_variants->getSizeVariant(SizeVariantType::ORIGINAL)->storage_disk->value;


Test patch: