我的下面的代码可以工作,除了上传部分。到目前为止,我可以毫无问题地加载脚本,并且当用户单击上传按钮时,文件对话框将打开。
但是,我想做的是将文件分配给包含其他文本输入和文本区域元素的表单。
基本上我正在尝试这样做:
- 用户在表单中填写值(即填写文本输入、文本区域字段)
- 用户使用 SWFUpload 选择文件
- 用户提交表单
是否可以将文件 Hook 到表单上的文件输入元素,以便在手动提交表单时,一次性发送所有值?
据我所知,SWFUpload 用于在后台自动提交文件...可以在一种表单上手动完成吗?
$('.swfupload-control').swfupload({
// File Upload Settings
file_size_limit : "102400", // 100MB
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : "10",
file_queue_limit : "0",
// Button Settings
button_image_url : "/images/upload_song.gif", // Relative to the SWF file
button_placeholder_id : "spanButtonPlaceholder",
button_width: 186,
button_height: 32,
// Flash Settings
flash_url : "/javascripts/swfupload/swfupload.swf"
});
$('.swfupload-control')
.bind('swfuploadLoaded', function(event){
$('#log').append('<li>Loaded</li>');
})
.bind('fileQueued', function(event, file){
$('#log').append('<li>File queued - '+file.name+'</li>');
//$('#song_attachment').val(file);
$('#update-media').parents('li').find('p').remove();
$('#update-media').parents('li').append('<p>'+(file.name.length >= 45 ? file.name.substr(0, 45) + '...' : file.name)+'</p>');
// start the upload since it's queued
//$(this).swfupload('startUpload');
})
.bind('fileQueueError', function(event, file, errorCode, message){
$('#log').append('<li>File queue error - '+message+'</li>');
})
.bind('fileDialogStart', function(event){
$('#log').append('<li>File dialog start</li>');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#log').append('<li>File dialog complete</li>');
})
.bind('uploadStart', function(event, file){
$('#log').append('<li>Upload start - '+file.name+'</li>');
})
.bind('uploadProgress', function(event, file, bytesLoaded){
$('#log').append('<li>Upload progress - '+bytesLoaded+'</li>');
})
.bind('uploadSuccess', function(event, file, serverData){
$('#log').append('<li>Upload success - '+file.name+'</li>');
})
.bind('uploadComplete', function(event, file){
$('#log').append('<li>Upload complete - '+file.name+'</li>');
// upload has completed, lets try the next one in the queue
$(this).swfupload('startUpload');
})
.bind('uploadError', function(event, file, errorCode, message){
$('#log').append('<li>Upload error - '+message+'</li>');
});
最佳答案
抱歉,我不知道 SWF 上传,如果不相关,我准备删除此答案...但是:
我在这里制作了两个应用程序:https://github.com/apneadiving/Pic-upload---Crop-in-Ajax
其中一个 Uploadify和一个带有 jQuery-File-Upload 。
它们都满足您的需求(ajax提交、多个文件上传)。我推荐 Jquery 文件上传,因为它是无 Flash 的。
我还在这里写了一个教程:https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3
关于javascript - SWFUpload 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5097067/