2011-04-17 01:18:06 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Init owncloud
|
|
|
|
require_once('../../lib/base.php');
|
|
|
|
|
|
|
|
// We send json data
|
|
|
|
// header( "Content-Type: application/json" );
|
|
|
|
// Firefox and Konqueror tries to download application/json for me. --Arthur
|
|
|
|
header( "Content-Type: text/plain" );
|
|
|
|
|
|
|
|
// Check if we are a user
|
2011-07-29 23:36:03 +04:00
|
|
|
if( !OC_User::isLoggedIn()){
|
2011-04-18 17:07:14 +04:00
|
|
|
echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
|
2011-04-17 01:18:06 +04:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2011-07-19 22:23:33 +04:00
|
|
|
$files=$_FILES['files'];
|
|
|
|
|
2011-04-17 01:18:06 +04:00
|
|
|
$dir = $_POST['dir'];
|
2011-08-21 16:28:44 +04:00
|
|
|
$dir .= '/';
|
2011-07-19 22:23:33 +04:00
|
|
|
$error='';
|
2011-08-15 22:37:50 +04:00
|
|
|
|
|
|
|
$totalSize=0;
|
|
|
|
foreach($files['size'] as $size){
|
|
|
|
$totalSize+=$size;
|
|
|
|
}
|
|
|
|
if($totalSize>OC_Filesystem::free_space('/')){
|
|
|
|
echo json_encode( array( "status" => "error", "data" => array( "message" => "Not enough space available" )));
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2011-07-19 22:23:33 +04:00
|
|
|
$result=array();
|
2011-04-17 13:27:28 +04:00
|
|
|
if(strpos($dir,'..') === false){
|
2011-07-19 22:23:33 +04:00
|
|
|
$fileCount=count($files['name']);
|
|
|
|
for($i=0;$i<$fileCount;$i++){
|
2011-08-20 20:36:20 +04:00
|
|
|
$target=stripslashes($dir) . $files['name'][$i];
|
2011-07-29 23:36:03 +04:00
|
|
|
if(OC_Filesystem::fromUploadedFile($files['tmp_name'][$i],$target)){
|
|
|
|
$result[]=array( "status" => "success", 'mime'=>OC_Filesystem::getMimeType($target),'size'=>OC_Filesystem::filesize($target),'name'=>$files['name'][$i]);
|
2011-07-19 22:23:33 +04:00
|
|
|
}
|
2011-04-17 01:18:06 +04:00
|
|
|
}
|
2011-07-19 22:23:33 +04:00
|
|
|
echo json_encode($result);
|
|
|
|
exit();
|
|
|
|
}else{
|
|
|
|
$error='invalid dir';
|
2011-04-17 01:18:06 +04:00
|
|
|
}
|
|
|
|
|
2011-04-19 11:13:50 +04:00
|
|
|
echo json_encode(array( 'status' => 'error', 'data' => array('error' => $error, "file" => $fileName)));
|
2011-04-17 01:18:06 +04:00
|
|
|
|
|
|
|
?>
|