当我点击plupload中的浏览按钮时,这可能是上传文件吗?

时间:2015-02-16 13:46:47

标签: plupload

在自定义api中

  <div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5     support.</div>
<div width="20px" id="progressbar"></div>
<div id="container">
  <a id="pickfiles" href="javascript:;">[Select files]</a> 
  <a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>

在这个当我们点击上传文件时,文件上传了bt我想要的时候我点击选择文件那个时候也上传文件。那么如果可能的话,我必须在脚本中做些什么改变?

 <script type="text/javascript">
 // Custom example logic
  var uploader = new plupload.Uploader({

//runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: document.getElementById('container'), // ... or DOM Element itself
url : 'upload.php',


filters : {
    max_file_size : '100mb',
    mime_types: [
        {title : "Image files", extensions : "jpg,gif,png"},
        {title : "Zip files", extensions : "zip"}
    ]
},

init: {
    PostInit: function() {
        document.getElementById('filelist').innerHTML = '';
        document.getElementById('uploadfiles').onclick = function() {
            uploader.start();
            return false;
        };


    },
    FilesAdded: function(up, files) {
        plupload.each(files, function(file) {
            document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div><br/>';

        });
    },
    UploadProgress: function(up, file) {
        document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
        $( "#progressbar" ).progressbar({
        value: false
        });

    },
      UploadComplete: function(up, files) {
            $( "#progressbar" ).progressbar({
            value: true
            });
        },

    Error: function(up, err) {
        document.getElementById('console').appendChild(document.createTextNode("Error #" + err.code + ": " + err.message +"\n"));
    }
}
});
uploader.init();

</script>

请帮帮我

1 个答案:

答案 0 :(得分:0)

您可以在FilesAdded事件中添加此内容。

试试这个:

FilesAdded: function(up, files) {
    plupload.each(files, function(file) {
        document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div><br/>';

    });
    up.start();
},