download.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Andreas Fischer <bantu@owncloud.com>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Frank Karlitschek <frank@karlitschek.de>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Piotr Filiciak <piotr@filiciak.pl>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. // Check if we are a user
  31. OCP\User::checkLoggedIn();
  32. \OC::$server->getSession()->close();
  33. $files = isset($_GET['files']) ? (string)$_GET['files'] : '';
  34. $dir = isset($_GET['dir']) ? (string)$_GET['dir'] : '';
  35. $files_list = json_decode($files);
  36. // in case we get only a single file
  37. if (!is_array($files_list)) {
  38. $files_list = [$files];
  39. }
  40. /**
  41. * this sets a cookie to be able to recognize the start of the download
  42. * the content must not be longer than 32 characters and must only contain
  43. * alphanumeric characters
  44. */
  45. if(isset($_GET['downloadStartSecret'])
  46. && !isset($_GET['downloadStartSecret'][32])
  47. && preg_match('!^[a-zA-Z0-9]+$!', $_GET['downloadStartSecret']) === 1) {
  48. setcookie('ocDownloadStarted', $_GET['downloadStartSecret'], time() + 20, '/');
  49. }
  50. $server_params = [ 'head' => \OC::$server->getRequest()->getMethod() === 'HEAD' ];
  51. /**
  52. * Http range requests support
  53. */
  54. if (isset($_SERVER['HTTP_RANGE'])) {
  55. $server_params['range'] = \OC::$server->getRequest()->getHeader('Range');
  56. }
  57. OC_Files::get($dir, $files_list, $server_params);