download.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Andreas Fischer <bantu@owncloud.com>
  6. * @author Felix Moeller <mail@felixmoeller.de>
  7. * @author Frank Karlitschek <frank@karlitschek.de>
  8. * @author Jakob Sack <mail@jakobsack.de>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Vincent Petry <pvince81@owncloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. $filename = $_GET["file"];
  30. if(!\OC\Files\Filesystem::file_exists($filename)) {
  31. header("HTTP/1.0 404 Not Found");
  32. $tmpl = new OCP\Template( '', '404', 'guest' );
  33. $tmpl->assign('file', $filename);
  34. $tmpl->printPage();
  35. exit;
  36. }
  37. $ftype=\OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType( $filename ));
  38. header('Content-Type:'.$ftype);
  39. OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
  40. OCP\Response::disableCaching();
  41. OCP\Response::setContentLengthHeader(\OC\Files\Filesystem::filesize($filename));
  42. OC_Util::obEnd();
  43. \OC\Files\Filesystem::readfile( $filename );