2013-08-17 05:16:48 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2013-08-17 05:16:48 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04: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 05:16:48 -04:00
|
|
|
*/
|
2014-04-20 10:12:46 -04:00
|
|
|
namespace OCP\AppFramework\Http;
|
2013-08-17 05:16:48 -04:00
|
|
|
|
2023-06-14 02:56:42 -04:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
|
|
2013-08-17 05:16:48 -04:00
|
|
|
/**
|
|
|
|
|
* Prompts the user to download the a file
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2024-12-16 10:20:48 -05:00
|
|
|
* @template S of Http::STATUS_*
|
2023-06-14 02:56:42 -04:00
|
|
|
* @template C of string
|
|
|
|
|
* @template H of array<string, mixed>
|
2024-12-16 10:20:48 -05:00
|
|
|
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
|
2013-08-17 05:16:48 -04:00
|
|
|
*/
|
2019-04-03 12:42:34 -04:00
|
|
|
class DownloadResponse extends Response {
|
2013-08-17 05:16:48 -04: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 02:56:42 -04:00
|
|
|
* @param C $contentType the mimetype that the downloaded file should have
|
|
|
|
|
* @param S $status
|
|
|
|
|
* @param H $headers
|
2015-04-16 11:00:08 -04:00
|
|
|
* @since 7.0.0
|
2013-08-17 05:16:48 -04:00
|
|
|
*/
|
2023-06-14 02:56:42 -04:00
|
|
|
public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) {
|
|
|
|
|
parent::__construct($status, $headers);
|
2019-04-03 12:42:34 -04:00
|
|
|
|
2021-06-02 12:59:43 -04:00
|
|
|
$filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']);
|
2013-08-17 05:16:48 -04:00
|
|
|
|
|
|
|
|
$this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
|
|
|
|
$this->addHeader('Content-Type', $contentType);
|
|
|
|
|
}
|
|
|
|
|
}
|