1
0

move.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Frank Karlitschek <frank@owncloud.org>
  5. * @author Georg Ehrke <georg@owncloud.com>
  6. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  7. * @author Lukas Reschke <lukas@owncloud.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <icewind@owncloud.com>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @copyright Copyright (c) 2015, 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. OCP\JSON::checkLoggedIn();
  29. OCP\JSON::callCheck();
  30. \OC::$server->getSession()->close();
  31. // Get data
  32. $dir = isset($_POST['dir']) ? (string)$_POST['dir'] : '';
  33. $file = isset($_POST['file']) ? (string)$_POST['file'] : '';
  34. $target = isset($_POST['target']) ? rawurldecode((string)$_POST['target']) : '';
  35. $l = \OC::$server->getL10N('files');
  36. if(\OC\Files\Filesystem::file_exists($target . '/' . $file)) {
  37. OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s - File with this name already exists", array($file)) )));
  38. exit;
  39. }
  40. if ($target != '' || strtolower($file) != 'shared') {
  41. $targetFile = \OC\Files\Filesystem::normalizePath($target . '/' . $file);
  42. $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
  43. try {
  44. if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
  45. OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
  46. } else {
  47. OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s", array($file)) )));
  48. }
  49. } catch (\OCP\Files\NotPermittedException $e) {
  50. OCP\JSON::error(array("data" => array( "message" => $l->t("Permission denied") )));
  51. } catch (\Exception $e) {
  52. OCP\JSON::error(array("data" => array( "message" => $e->getMessage())));
  53. }
  54. }else{
  55. OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s", array($file)) )));
  56. }