jQuery fileupload - 获取上传文件的列表 [英] jQuery fileupload - get list of uploaded files

查看:398
本文介绍了jQuery fileupload - 获取上传文件的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用非常好的jquery插件 blueimp / jQuery-File-Upload

  $('#fileupload')。fileupload({
autoUpload:true
,filesContainer:' #attachments_presentation tbody'
,stop:function(e){
console.log(data);
}
});

我无法做很简单的事情:获取上传的文件列表

(在服务器上有它们的名字)

首先,我天真的将它存储在文件输入中,所以我可以用

  $('#fileupload')。val(); 

但是不是这样,所以我想说一下类似于

  $('#fileupload')。fileupload('getfiles'); 

我无法从文档中找到方法

有人可以告诉我如何获取服务器上传的文件名列表吗?






更新



我想在服务器上获取上传的文件名称,以便能够管理它们。
$ b

例如:


  • 我上传一个名为 trutruc.pdf

  • 我上传 test.png
  • li>我重新上传一个名为 trutruc.pdf 的文件
  • 删除第一个文件


服务器中当前的文件列表应该是 test.png trutruc( 2).pdf






更新2



我使用默认的PHP脚本出货无线当你实例化默认的插件时,会有一个代码部分检索所有以前上传的文件(假设你没有改变服务器的代码):



请参阅 main.js 文件行70:

  //加载现有文件:
$ .ajax({
//取消注释以下内容以发送跨域cookie:
// xhrFields:{withCredentials:true},$ b $ url:$('#fileupload')。fileupload('option','url'),
dataType:'json' ,
context:$('#fileupload')[0]
})。done(function(result){
$(this).fileupload('option','done')
.call(this,null,{result:result});
});

如果你仔细观察你的代码,会看到一个表格, :

 < table role =presentationclass =table table-striped>< tbody class =files data-toggle =modal-gallerydata-target =#modal-gallery>< / tbody>< / table> 

加载文件后,您可以轻松解析每个表格:

  $('tbody.files tr')。each(function(i,e){
//根据@ Brandon的评论现在是p。 ();
var name = $(e).find('td.size')。text() ;
//等
});


I'm using the very good jquery plugin blueimp / jQuery-File-Upload

$('#fileupload').fileupload({
  autoUpload: true
, filesContainer: '#attachments_presentation tbody'
, stop: function (e) {
    console.log(data);
  }
});

And I'm not able to do something very simple: get the list of uploaded files
(with their name on the server)

Firstly I naively though it would be stored on the file input so I could get the list with

$('#fileupload').val();

But it's not, so I though about something like

$('#fileupload').fileupload('getfiles');

I can't find the way from the docs

Can somebody tell me how I can get the list of uploaded file names in the server ?


Update

I'd like to get the uploaded files name on the server in order to be able to manage them afterwards.

For example:

  • I upload a file named trutruc.pdf
  • I upload test.png
  • I re-upload a file named trutruc.pdf
  • I delete the first file

The current list of files in the server should then be test.png, trutruc (2).pdf


Update 2

I'm using the default php script shipped with fileUpload

解决方案

When you instantiate the default plugin, there is a code portion which is retrieving all the previous uploaded files (assuming you haven't changed the server code) :

See on the main.js file line 70 :

    // Load existing files:
    $.ajax({
    // Uncomment the following to send cross-domain cookies:
    //xhrFields: {withCredentials: true},
    url: $('#fileupload').fileupload('option', 'url'),
        dataType: 'json',
        context: $('#fileupload')[0]
    }).done(function (result) {
        $(this).fileupload('option', 'done')
            .call(this, null, {result: result});
    });

Than if you look further in your code, there is a table which will be filled out with the template :

<table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>

You could easily parse each from that table after loading the files :

$('tbody.files tr').each(function(i, e) {
    //according to @Brandon's comment it's now p.name
    var name = $(e).find('td.name').text(); 
    var size = $(e).find('td.size').text();
    //etc.
});

这篇关于jQuery fileupload - 获取上传文件的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆