download.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * @author Felix Moeller <mail@felixmoeller.de>
  4. * @author Frank Karlitschek <frank@owncloud.org>
  5. * @author Jakob Sack <mail@jakobsack.de>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Vincent Petry <pvince81@owncloud.com>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. // Check if we are a user
  28. OCP\User::checkLoggedIn();
  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_Helper::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 );