preview.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : '';
  10. $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36';
  11. $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36';
  12. $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true;
  13. if($file === '') {
  14. //400 Bad Request
  15. \OC_Response::setStatus(400);
  16. \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
  17. exit;
  18. }
  19. if($maxX === 0 || $maxY === 0) {
  20. //400 Bad Request
  21. \OC_Response::setStatus(400);
  22. \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
  23. exit;
  24. }
  25. try{
  26. $preview = new \OC\Preview(\OC_User::getUser(), 'files');
  27. $preview->setFile($file);
  28. $preview->setMaxX($maxX);
  29. $preview->setMaxY($maxY);
  30. $preview->setScalingUp($scalingUp);
  31. $preview->show();
  32. }catch(\Exception $e) {
  33. \OC_Response::setStatus(500);
  34. \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
  35. }