move.php 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. OCP\JSON::checkLoggedIn();
  3. OCP\JSON::callCheck();
  4. \OC::$session->close();
  5. // Get data
  6. $dir = stripslashes($_POST["dir"]);
  7. $file = stripslashes($_POST["file"]);
  8. $target = stripslashes(rawurldecode($_POST["target"]));
  9. $l = OC_L10N::get('files');
  10. if(\OC\Files\Filesystem::file_exists($target . '/' . $file)) {
  11. OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s - File with this name already exists", array($file)) )));
  12. exit;
  13. }
  14. if ($target != '' || strtolower($file) != 'shared') {
  15. $targetFile = \OC\Files\Filesystem::normalizePath($target . '/' . $file);
  16. $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
  17. if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
  18. OCP\JSON::success(array("data" => array( "dir" => $dir, "files" => $file )));
  19. } else {
  20. OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s", array($file)) )));
  21. }
  22. }else{
  23. OCP\JSON::error(array("data" => array( "message" => $l->t("Could not move %s", array($file)) )));
  24. }