我已成功使用plupload及其浏览按钮选项,但我现在正尝试使用该实用程序调整用户单独选择文件的现有网页中的文件大小。 我从文档中了解到,上传器addFile方法可以使用输入字段,但我没有成功。
该字段定义为:
<input id="SelectUserFile1" name="userfile1" type="file" accept="image/gif,image/jpeg" aria-labelledby="SelectUserFile1-ariaLabel" title="Browse for file on your computer" />
我将文件添加到:
uploader.init();
uploader.addFile(document.getElementById('SelectUserFile1'));
alert('files total: ' + uploader.files.length);
uploader.start();
但似乎失败了,因为我的FilesAdded方法没有被调用,uploader.files.length是0。 我的上传者定义如下:
var filecount = 1;
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
url : 'test_file_upload.php',
flash_swf_url : '../testjs/Moxie.swf',
silverlight_xap_url : '../testjs/Moxie.xap',
resize: {
width: 500,
height: 500
},
filters : {
max_file_size : '5mb',
mime_types: [
{title : "Image files", extensions : "jpg,gif"}
]
},
// PreInit events, bound before any internal events
preinit: {
UploadFile: function(up, file) {
//log('[UploadFile]', file);
// You can override settings before the file is uploaded
up.settings.url = 'test_file_upload.php?cnt=' + filecount;
filecount = filecount + 1;
}
},
init: {
FilesAdded: function(up, files) {
alert('files added: ' + up.files.length);
},
Error: function(up, err) {
alert( err.message + ' File not included.' );
}
}
});
我做错了什么?