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 Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Piotr Filiciak <piotr@filiciak.pl>
  12. * @author Robin Appelman <robin@icewind.nl>
  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. // Check if we are a user
  30. OCP\User::checkLoggedIn();
  31. \OC::$server->getSession()->close();
  32. $files = isset($_GET['files']) ? (string)$_GET['files'] : '';
  33. $dir = isset($_GET['dir']) ? (string)$_GET['dir'] : '';
  34. $files_list = json_decode($files);
  35. // in case we get only a single file
  36. if (!is_array($files_list)) {
  37. $files_list = array($files);
  38. }
  39. /**
  40. * this sets a cookie to be able to recognize the start of the download
  41. * the content must not be longer than 32 characters and must only contain
  42. * alphanumeric characters
  43. */
  44. if(isset($_GET['downloadStartSecret'])
  45. && !isset($_GET['downloadStartSecret'][32])
  46. && preg_match('!^[a-zA-Z0-9]+$!', $_GET['downloadStartSecret']) === 1) {
  47. setcookie('ocDownloadStarted', $_GET['downloadStartSecret'], time() + 20, '/');
  48. }
  49. $server_params = array( 'head' => \OC::$server->getRequest()->getMethod() == 'HEAD' );
  50. /**
  51. * Http range requests support
  52. */
  53. if (isset($_SERVER['HTTP_RANGE'])) {
  54. $server_params['range'] = \OC::$server->getRequest()->getHeader('Range');
  55. }
  56. OC_Files::get($dir, $files_list, $server_params);