newfolder.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Björn Schießle <schiessle@owncloud.com>
  5. * @author Frank Karlitschek <frank@owncloud.org>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Lukas Reschke <lukas@owncloud.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <icewind@owncloud.com>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Vincent Petry <pvince81@owncloud.com>
  13. *
  14. * @copyright Copyright (c) 2015, ownCloud, Inc.
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. // Init owncloud
  31. OCP\JSON::checkLoggedIn();
  32. OCP\JSON::callCheck();
  33. \OC::$server->getSession()->close();
  34. // Get the params
  35. $dir = isset($_POST['dir']) ? (string)$_POST['dir'] : '';
  36. $folderName = isset($_POST['foldername']) ?(string) $_POST['foldername'] : '';
  37. $l10n = \OC::$server->getL10N('files');
  38. $result = array(
  39. 'success' => false,
  40. 'data' => NULL
  41. );
  42. try {
  43. \OC\Files\Filesystem::getView()->verifyPath($dir, $folderName);
  44. } catch (\OCP\Files\InvalidPathException $ex) {
  45. $result['data'] = [
  46. 'message' => $ex->getMessage()];
  47. OCP\JSON::error($result);
  48. return;
  49. }
  50. if (!\OC\Files\Filesystem::file_exists($dir . '/')) {
  51. $result['data'] = array('message' => (string)$l10n->t(
  52. 'The target folder has been moved or deleted.'),
  53. 'code' => 'targetnotfound'
  54. );
  55. OCP\JSON::error($result);
  56. exit();
  57. }
  58. $target = $dir . '/' . $folderName;
  59. if (\OC\Files\Filesystem::file_exists($target)) {
  60. $result['data'] = array('message' => $l10n->t(
  61. 'The name %s is already used in the folder %s. Please choose a different name.',
  62. array($folderName, $dir))
  63. );
  64. OCP\JSON::error($result);
  65. exit();
  66. }
  67. if(\OC\Files\Filesystem::mkdir($target)) {
  68. if ( $dir !== '/') {
  69. $path = $dir.'/'.$folderName;
  70. } else {
  71. $path = '/'.$folderName;
  72. }
  73. $meta = \OC\Files\Filesystem::getFileInfo($path);
  74. $meta['type'] = 'dir'; // missing ?!
  75. OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
  76. exit();
  77. }
  78. OCP\JSON::error(array('data' => array( 'message' => $l10n->t('Error when creating the folder') )));