Provide ability to select mutliply files during upload for browsers that support it.

remotes/origin/stable
Robin Appelman 14 years ago
parent 24e81ce4d5
commit b69ae10b74
  1. 22
      files/ajax/upload.php
  2. 30
      files/js/files.js
  3. 2
      files/templates/index.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)));
?>

@ -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() {

@ -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>

Loading…
Cancel
Save