2011-10-23 09:40:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Init owncloud
|
2012-04-17 17:31:29 +00:00
|
|
|
|
2011-10-23 09:40:40 +00:00
|
|
|
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2011-10-23 09:40:40 +00:00
|
|
|
|
|
|
|
// Get the params
|
2012-03-07 20:43:44 +00:00
|
|
|
$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']) : '';
|
2011-10-23 09:40:40 +00:00
|
|
|
|
|
|
|
if($filename == '') {
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::error(array("data" => array( "message" => "Empty Filename" )));
|
2011-10-23 09:40:40 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2012-03-07 20:43:44 +00:00
|
|
|
if($source){
|
|
|
|
if(substr($source,0,8)!='https://' and substr($source,0,7)!='http://'){
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::error(array("data" => array( "message" => "Not a valid source" )));
|
2012-03-07 20:43:44 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
$sourceStream=fopen($source,'rb');
|
|
|
|
$target=$dir.'/'.$filename;
|
|
|
|
$result=OC_Filesystem::file_put_contents($target,$sourceStream);
|
|
|
|
if($result){
|
|
|
|
$mime=OC_Filesystem::getMimetype($target);
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::success(array("data" => array('mime'=>$mime)));
|
2012-03-07 20:43:44 +00:00
|
|
|
exit();
|
|
|
|
}else{
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::error(array("data" => array( "message" => "Error while downloading ".$source. ' to '.$target )));
|
2012-03-07 20:43:44 +00:00
|
|
|
exit();
|
|
|
|
}
|
2012-05-05 14:47:23 +00:00
|
|
|
}else{
|
2011-10-23 09:40:40 +00:00
|
|
|
if($content){
|
2012-05-05 14:47:23 +00:00
|
|
|
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();
|
2011-10-23 09:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::error(array("data" => array( "message" => "Error when creating the file" )));
|