summaryrefslogtreecommitdiffstats
path: root/files/ajax/newfile.php
diff options
context:
space:
mode:
Diffstat (limited to 'files/ajax/newfile.php')
-rw-r--r--files/ajax/newfile.php26
1 files changed, 23 insertions, 3 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);