DownloadResponse.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP\AppFramework\Http;
  27. /**
  28. * Prompts the user to download the a file
  29. * @since 7.0.0
  30. */
  31. class DownloadResponse extends Response {
  32. /**
  33. * Creates a response that prompts the user to download the file
  34. * @param string $filename the name that the downloaded file should have
  35. * @param string $contentType the mimetype that the downloaded file should have
  36. * @since 7.0.0
  37. */
  38. public function __construct(string $filename, string $contentType) {
  39. parent::__construct();
  40. $filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']);
  41. $this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
  42. $this->addHeader('Content-Type', $contentType);
  43. }
  44. }