newfolder.php 896 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. // Init owncloud
  3. OCP\JSON::checkLoggedIn();
  4. OCP\JSON::callCheck();
  5. // Get the params
  6. $dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : '';
  7. $foldername = isset( $_POST['foldername'] ) ? stripslashes($_POST['foldername']) : '';
  8. if(trim($foldername) == '') {
  9. OCP\JSON::error(array("data" => array( "message" => "Empty Foldername" )));
  10. exit();
  11. }
  12. if(strpos($foldername, '/')!==false) {
  13. OCP\JSON::error(array("data" => array( "message" => "Invalid Foldername" )));
  14. exit();
  15. }
  16. if(\OC\Files\Filesystem::mkdir($dir . '/' . stripslashes($foldername))) {
  17. if ( $dir != '/') {
  18. $path = $dir.'/'.$foldername;
  19. } else {
  20. $path = '/'.$foldername;
  21. }
  22. $meta = \OC\Files\Filesystem::getFileInfo($path);
  23. $id = $meta['fileid'];
  24. OCP\JSON::success(array("data" => array('id'=>$id)));
  25. exit();
  26. }
  27. OCP\JSON::error(array("data" => array( "message" => "Error when creating the folder" )));