You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preview.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. \OC_Util::checkLoggedIn();
  9. \OC::$server->getSession()->close();
  10. $file = array_key_exists('file', $_GET) ? (string)$_GET['file'] : '';
  11. $maxX = array_key_exists('x', $_GET) ? (int)$_GET['x'] : '36';
  12. $maxY = array_key_exists('y', $_GET) ? (int)$_GET['y'] : '36';
  13. $scalingUp = array_key_exists('scalingup', $_GET) ? (bool)$_GET['scalingup'] : true;
  14. $keepAspect = array_key_exists('a', $_GET) ? true : false;
  15. $always = array_key_exists('forceIcon', $_GET) ? (bool)$_GET['forceIcon'] : true;
  16. if ($file === '') {
  17. //400 Bad Request
  18. \OC_Response::setStatus(400);
  19. \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
  20. exit;
  21. }
  22. if ($maxX === 0 || $maxY === 0) {
  23. //400 Bad Request
  24. \OC_Response::setStatus(400);
  25. \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
  26. exit;
  27. }
  28. $preview = new \OC\Preview(\OC_User::getUser(), 'files');
  29. $info = \OC\Files\Filesystem::getFileInfo($file);
  30. if (!$info instanceof OCP\Files\FileInfo || !$always && !$preview->isAvailable($info)) {
  31. \OC_Response::setStatus(404);
  32. } else {
  33. $preview->setFile($file);
  34. $preview->setMaxX($maxX);
  35. $preview->setMaxY($maxY);
  36. $preview->setScalingUp($scalingUp);
  37. $preview->setKeepAspect($keepAspect);
  38. $preview->showPreview();
  39. }