download.php 1.9 KB

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