blob: 7236deb65c9b934791731a97fde4de227076bc06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get the params
$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 == '') {
OCP\JSON::error(array("data" => array( "message" => "Empty Filename" )));
exit();
}
if(strpos($filename,'/')!==false){
OCP\JSON::error(array("data" => array( "message" => "Invalid Filename" )));
exit();
}
if($source){
if(substr($source,0,8)!='https://' and substr($source,0,7)!='http://'){
OCP\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);
OCP\JSON::success(array("data" => array('mime'=>$mime)));
exit();
}else{
OCP\JSON::error(array("data" => array( "message" => "Error while downloading ".$source. ' to '.$target )));
exit();
}
}else{
if($content){
if(OC_Filesystem::file_put_contents($dir.'/'.$filename,$content)){
OCP\JSON::success(array("data" => array('content'=>$content)));
exit();
}
}elseif(OC_Files::newFile($dir, $filename, 'file')){
OCP\JSON::success(array("data" => array('content'=>$content)));
exit();
}
}
OCP\JSON::error(array("data" => array( "message" => "Error when creating the file" )));
|