newfile.php 687 B

123456789101112131415161718192021222324252627
  1. <?php
  2. // Init owncloud
  3. require_once('../../lib/base.php');
  4. OC_JSON::checkLoggedIn();
  5. // Get the params
  6. $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
  7. $filename = isset( $_GET['filename'] ) ? $_GET['filename'] : '';
  8. $content = isset( $_GET['content'] ) ? $_GET['content'] : '';
  9. if($filename == '') {
  10. OC_JSON::error(array("data" => array( "message" => "Empty Filename" )));
  11. exit();
  12. }
  13. if(OC_Files::newFile($dir, $filename, 'file')) {
  14. if($content){
  15. OC_Filesystem::file_put_contents($dir.'/'.$filename,$content);
  16. }
  17. OC_JSON::success(array("data" => array('content'=>$content)));
  18. exit();
  19. }
  20. OC_JSON::error(array("data" => array( "message" => "Error when creating the file" )));