diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-03-07 21:43:44 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-03-07 21:43:44 +0100 |
commit | 018f0c4b72d9d2ca1c27c4c543a805b227745beb (patch) | |
tree | 8d4bc4d73f576331a8b8f6ffc55b6a141b8d54c1 /files/ajax | |
parent | cf5d63f0abc2b4537098962ad5051180861f965b (diff) | |
download | nextcloud-server-018f0c4b72d9d2ca1c27c4c543a805b227745beb.tar.gz nextcloud-server-018f0c4b72d9d2ca1c27c4c543a805b227745beb.zip |
add option to add file from url
Diffstat (limited to 'files/ajax')
-rw-r--r-- | files/ajax/newfile.php | 26 | ||||
-rw-r--r-- | files/ajax/newfolder.php | 4 |
2 files changed, 25 insertions, 5 deletions
diff --git a/files/ajax/newfile.php b/files/ajax/newfile.php index afc444bc0ac..2d1372f06ee 100644 --- a/files/ajax/newfile.php +++ b/files/ajax/newfile.php @@ -6,15 +6,35 @@ require_once('../../lib/base.php'); OC_JSON::checkLoggedIn(); // Get the params -$dir = isset( $_GET['dir'] ) ? stripslashes($_GET['dir']) : ''; -$filename = isset( $_GET['filename'] ) ? stripslashes($_GET['filename']) : ''; -$content = isset( $_GET['content'] ) ? $_GET['content'] : ''; +$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : ''; +$filename = isset( $_POST['filename'] ) ? stripslashes($_POST['filename']) : ''; +$content = isset( $_POST['content'] ) ? $_POST['content'] : ''; +$source = isset( $_POST['source'] ) ? stripslashes($_POST['source']) : ''; if($filename == '') { OC_JSON::error(array("data" => array( "message" => "Empty Filename" ))); exit(); } +if($source){ + if(substr($source,0,8)!='https://' and substr($source,0,7)!='http://'){ + OC_JSON::error(array("data" => array( "message" => "Not a valid source" ))); + exit(); + } + $sourceStream=fopen($source,'rb'); + $target=$dir.'/'.$filename; + $result=OC_Filesystem::file_put_contents($target,$sourceStream); + if($result){ + $mime=OC_Filesystem::getMimetype($target); + OC_JSON::success(array("data" => array('mime'=>$mime))); + exit(); + }else{ + OC_JSON::error(array("data" => array( "message" => "Error while downloading ".$source. ' to '.$target ))); + exit(); + } +} + + if(OC_Files::newFile($dir, $filename, 'file')) { if($content){ OC_Filesystem::file_put_contents($dir.'/'.$filename,$content); diff --git a/files/ajax/newfolder.php b/files/ajax/newfolder.php index 6db045c4e17..228e369fbef 100644 --- a/files/ajax/newfolder.php +++ b/files/ajax/newfolder.php @@ -6,8 +6,8 @@ require_once('../../lib/base.php'); OC_JSON::checkLoggedIn(); // Get the params -$dir = isset( $_GET['dir'] ) ? stripslashes($_GET['dir']) : ''; -$foldername = isset( $_GET['foldername'] ) ? stripslashes($_GET['foldername']) : ''; +$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : ''; +$foldername = isset( $_POST['foldername'] ) ? stripslashes($_POST['foldername']) : ''; if(trim($foldername) == '') { OC_JSON::error(array("data" => array( "message" => "Empty Foldername" ))); |