2013-08-17 11:16:48 +02:00
|
|
|
<?php
|
2024-05-23 09:26:56 +02:00
|
|
|
|
2013-08-17 11:16:48 +02:00
|
|
|
/**
|
2024-05-23 09:26:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-08-17 11:16:48 +02:00
|
|
|
*/
|
2014-04-20 16:12:46 +02:00
|
|
|
namespace OCP\AppFramework\Http;
|
2013-08-17 11:16:48 +02:00
|
|
|
|
2023-06-14 08:56:42 +02:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
|
2013-08-17 11:16:48 +02:00
|
|
|
/**
|
|
|
|
* Prompts the user to download the a file
|
2015-04-16 17:00:08 +02:00
|
|
|
* @since 7.0.0
|
2024-12-16 16:20:48 +01:00
|
|
|
* @template S of Http::STATUS_*
|
2023-06-14 08:56:42 +02:00
|
|
|
* @template C of string
|
|
|
|
* @template H of array<string, mixed>
|
2024-12-16 16:20:48 +01:00
|
|
|
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
|
2013-08-17 11:16:48 +02:00
|
|
|
*/
|
2019-04-03 18:42:34 +02:00
|
|
|
class DownloadResponse extends Response {
|
2013-08-17 11:16:48 +02:00
|
|
|
/**
|
|
|
|
* Creates a response that prompts the user to download the file
|
|
|
|
* @param string $filename the name that the downloaded file should have
|
2023-06-14 08:56:42 +02:00
|
|
|
* @param C $contentType the mimetype that the downloaded file should have
|
|
|
|
* @param S $status
|
|
|
|
* @param H $headers
|
2015-04-16 17:00:08 +02:00
|
|
|
* @since 7.0.0
|
2013-08-17 11:16:48 +02:00
|
|
|
*/
|
2023-06-14 08:56:42 +02:00
|
|
|
public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) {
|
|
|
|
parent::__construct($status, $headers);
|
2019-04-03 18:42:34 +02:00
|
|
|
|
2021-06-02 18:59:43 +02:00
|
|
|
$filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']);
|
2013-08-17 11:16:48 +02:00
|
|
|
|
|
|
|
$this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
|
|
|
$this->addHeader('Content-Type', $contentType);
|
|
|
|
}
|
|
|
|
}
|