简体   繁体   English

在plupload ui中成功上传后如何获取/打印文件名

[英]How to get/print file name after successful upload in plupload ui

I do not have much knowledge in javascript. 我对javascript不太了解。 I am trying to get and print file name in a input box after a successful upload event. 上载成功后,我试图在输入框中获取并打印文件名。 I'm using plupload ui widget. 我正在使用plupload ui小部件。 the below script works fine, I can upload files but I cant get file name after the upload finishes. 以下脚本可以正常工作,我可以上传文件,但上传完成后无法获取文件名。 I have googled a lot but couldn't get it working. 我在Google上搜索了很多,但无法正常运行。 here is the code I'm using.. 这是我正在使用的代码。

// Initialize the widget when the DOM is ready
$(function() {
    $("#uploader").plupload({
        // General settings
        runtimes : 'html5,flash,silverlight,html4',
        url : 'upload.php',

        // User can upload no more then 20 files in one go (sets multiple_queues to false)
        max_file_count: 20,

        chunk_size: '1mb',


        filters : {
            // Maximum file size
            max_file_size : '10mb',
            // Specify what files to browse for
            mime_types: [
            {title : "Image files", extensions : "jpg,gif,png"},
    {title : "Zip files", extensions : "zip"}
        ]
        },

        // Rename files by clicking on their titles
        rename: true,

        // Sort files
        sortable: true,

        // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
        dragdrop: true,
        prevent_duplicates: true,

        // Views to activate
        views: {
            list: true,
            thumbs: true, // Show thumbs
            active: 'thumbs'
        },

        // Flash settings
        flash_swf_url : 'js/Moxie.swf',

        // Silverlight settings
        silverlight_xap_url : 'js/Moxie.xap'
        });

uploader.bind('FileUploaded' , function(up, file, response ) {
if ( (Uploader.total.uploaded + 1) == Uploader.files.length)
{
alert(File.name);
};
})


    // Handle the case when form was submitted before uploading has finished
    $('form').submit(function(e) {
var uploader = $('#uploader').plupload('getUploader');
        // Files in queue upload them first
        if (uploader.files.length > 0) {
        // When all files are uploaded submit form
            uploader.bind('StateChanged', function() {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                $('form')[0].getlink();
}
            });

            uploader.start();
        } else {
            alert("You must have at least one file in the queue.");
        }
        return false; // Keep the form from submitting
    });
});

You have a faulty conditional in your FileUploaded handler: 您的FileUploaded处理程序中的条件错误:

if ( (Uploader.total.uploaded + 1) == Uploader.files.length)

Why Uploader.total.uploaded + 1 ? 为什么Uploader.total.uploaded + 1 It will never get fulfilled. 它永远不会实现。

Also Plupload UI widget has it's own syntax for attaching handlers to the events. 另外,Plupload UI小部件具有它自己的语法,用于将处理程序附加到事件。

// Subscribing to the events...
// ... on initialization:
$('#uploader').plupload({
  ...
  viewchanged: function(event, args) {
    // stuff ...
  }
});
// ... or after initialization
$('#uploader').on("viewchanged", function(event, args) {
  // stuff ...
});

Consider the following playground sample . 请考虑以下游乐场样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM