download.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  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. OCP\JSON::checkAppEnabled('files_versions');
  28. OCP\JSON::checkLoggedIn();
  29. $file = $_GET['file'];
  30. $revision=(int)$_GET['revision'];
  31. list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file);
  32. $versionName = '/'.$uid.'/files_versions/'.$filename.'.v'.$revision;
  33. $view = new OC\Files\View('/');
  34. $ftype = \OC::$server->getMimeTypeDetector()->getSecureMimeType($view->getMimeType('/'.$uid.'/files/'.$filename));
  35. header('Content-Type:'.$ftype);
  36. OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
  37. OCP\Response::disableCaching();
  38. OCP\Response::setContentLengthHeader($view->filesize($versionName));
  39. OC_Util::obEnd();
  40. $view->readfile($versionName);