0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-05-18 12:11:41 +00:00
nextcloud_server/lib/public/AppFramework/Http/DownloadResponse.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2013-08-17 11:16:48 +02:00
<?php
2013-08-17 11:16:48 +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
*/
namespace OCP\AppFramework\Http;
2013-08-17 11:16:48 +02:00
use OCP\AppFramework\Http;
2013-08-17 11:16:48 +02:00
/**
* 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>>
2013-08-17 11:16:48 +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
* @param C $contentType the mimetype that the downloaded file should have
* @param S $status
* @param H $headers
* @since 7.0.0
2013-08-17 11:16:48 +02:00
*/
public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) {
parent::__construct($status, $headers);
$filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']);
2013-08-17 11:16:48 +02:00
$this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
$this->addHeader('Content-Type', $contentType);
}
}