aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--files/ajax/upload.php22
-rw-r--r--files/js/files.js30
-rw-r--r--files/templates/index.php2
3 files changed, 36 insertions, 18 deletions
diff --git a/files/ajax/upload.php b/files/ajax/upload.php
index effee0c03c1..f47f9b3d282 100644
--- a/files/ajax/upload.php
+++ b/files/ajax/upload.php
@@ -14,20 +14,26 @@ if( !OC_USER::isLoggedIn()){
exit();
}
-$fileName=$_FILES['file']['name'];
-$source=$_FILES['file']['tmp_name'];
+$files=$_FILES['files'];
+
$dir = $_POST['dir'];
if(!empty($dir)) $dir .= '/';
-$target='/' . stripslashes($dir) . $fileName;
+$error='';
+$result=array();
if(strpos($dir,'..') === false){
- if(OC_FILESYSTEM::fromUploadedFile($source,$target)){
- echo json_encode(array( "status" => "success", 'mime'=>OC_FILESYSTEM::getMimeType($target),'size'=>OC_FILESYSTEM::filesize($target)));
- exit();
+ $fileCount=count($files['name']);
+ for($i=0;$i<$fileCount;$i++){
+ $target='/' . stripslashes($dir) . $files['name'][$i];
+ 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]);
+ }
}
+ echo json_encode($result);
+ exit();
+}else{
+ $error='invalid dir';
}
-$error = $_FILES['file']['error'];
-
echo json_encode(array( 'status' => 'error', 'data' => array('error' => $error, "file" => $fileName)));
?>
diff --git a/files/js/files.js b/files/js/files.js
index 3c02110fe26..9d05b3776fe 100644
--- a/files/js/files.js
+++ b/files/js/files.js
@@ -150,27 +150,39 @@ $(document).ready(function() {
$('#file_upload_submit').click(function(){
var name=$('#file_upload_filename').val();
- if($('#file_upload_start')[0].files[0] && $('#file_upload_start')[0].files[0].size>0){
- var size=simpleFileSize($('#file_upload_start')[0].files[0].size);
- }else{
- var size='Pending';
- }
+ var files=$('#file_upload_start')[0].files;
$('#file_upload_target').load(function(){
var response=jQuery.parseJSON($('#file_upload_target').contents().find('body').text());
//set mimetype and if needed filesize
- $('tr[data-file="'+name+'"]').attr('data-mime',response.mime);
- if(size=='Pending'){
- $('tr[data-file='+name+'] td.filesize').text(response.size);
+ for(var i=0;i<response.length;i++){
+ var file=response[i];
+ $('tr[data-file="'+file.name+'"]').attr('data-mime',file.mime);
+ if(size=='Pending'){
+ $('tr[data-file='+file.name+'] td.filesize').text(file.size);
+ }
}
});
$('#file_upload_form').submit();
var date=new Date();
var uploadTime=formatDate(date);
- FileList.addFile(name,size,uploadTime);
+ for(var i=0;i<files.length;i++){
+ if(files[i].size>0){
+ var size=simpleFileSize(files[i].size);
+ }else{
+ var size='Pending';
+ }
+ FileList.addFile(files[i].name,size,uploadTime);
+ }
$('#file_upload_filename').val($('#file_upload_filename').data('upload_text'));
+ $('#file_upload_submit').hide();
});
//save the original upload button text
$('#file_upload_filename').data('upload_text',$('#file_upload_filename').val());
+
+ //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used)
+ if(navigator.userAgent.search(/konqueror/i)==-1){
+ $('#file_upload_start').attr('multiple','multiple')
+ }
});
var adjustNewFolderSize = function() {
diff --git a/files/templates/index.php b/files/templates/index.php
index a1254eeb423..e2760d80da0 100644
--- a/files/templates/index.php
+++ b/files/templates/index.php
@@ -6,7 +6,7 @@
<input type="hidden" name="dir" value="<?php echo $_["dir"] ?>" id="dir">
<div id='file_upload_wrapper'>
<input class="prettybutton" id='file_upload_filename' value="Upload (max. <?php echo $_["uploadMaxHumanFilesize"];?>)"/>
- <input class="prettybutton" type="file" id="file_upload_start" name='file'/>
+ <input class="prettybutton" type="file" id="file_upload_start" name='files[]'/>
</div>&nbsp;
<input class="prettybutton" type="button" id="file_upload_submit" name="file_upload_submit" value="OK" />
<iframe id="file_upload_target" name="file_upload_target" src=""></iframe>