diff options
Diffstat (limited to 'lib/public/AppFramework/Http/DownloadResponse.php')
-rw-r--r-- | lib/public/AppFramework/Http/DownloadResponse.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/public/AppFramework/Http/DownloadResponse.php b/lib/public/AppFramework/Http/DownloadResponse.php new file mode 100644 index 00000000000..190de022d36 --- /dev/null +++ b/lib/public/AppFramework/Http/DownloadResponse.php @@ -0,0 +1,37 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCP\AppFramework\Http; + +use OCP\AppFramework\Http; + +/** + * Prompts the user to download the a file + * @since 7.0.0 + * @template S of Http::STATUS_* + * @template C of string + * @template H of array<string, mixed> + * @template-extends Response<Http::STATUS_*, array<string, mixed>> + */ +class DownloadResponse extends Response { + /** + * Creates a response that prompts the user to download the file + * @param string $filename the name that the downloaded file should have + * @param C $contentType the mimetype that the downloaded file should have + * @param S $status + * @param H $headers + * @since 7.0.0 + */ + public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) { + parent::__construct($status, $headers); + + $filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']); + + $this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); + $this->addHeader('Content-Type', $contentType); + } +} |