我在这个问题http://demo.swfupload.org/v220/simpledemo/index.php
中引用了simpledemo我希望能够传递一个由下拉菜单设置的变量。
上传者由
发起var swfu;
window.onload = function() {
var settings = {
flash_url : "<?php global_data::show_admin_dir(); ?>SWFUpload v2.2.0.1 Samples/demos/swfupload/swfupload.swf",
upload_url: "<?php global_data::show_admin_dir(); ?>upload.php",
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>" },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// Button settings
button_image_url: "images/TestImageNoText_65x29.png",
button_width: "95",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">UPLOAD</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
,表格如下
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p><label>Category: </label><input type="radio" name="for" class="radio" value="category" checked="checked" /><select name="foo"><option>...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<p><label>Product: </label><input type="radio" name="for" class="radio" value="category" /><select disabled="disabled"><option name="foo">...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
</form>
如果有人能指出我正确的方向,那将非常感激。
######编辑##### 我可能找到了办法...
使用post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "PR" : thing },
在init设置中并将其全部包装在函数中
function loader( thing ) {
....
}
然后使用
$(document).ready(function(){
$('select[name=foo]').change(function(){
loader( $(':selected', this).text() );
});
});
它会起作用,但是如果我在上传之前第二次更改选择选项会收到错误并且只发送第一个选择而不是第二个...
答案 0 :(得分:1)
我试图做类似的事情,在找到这个解决方案并与我的同事讨论之后,我们使用swfupload提供的Javascript API解决了另一种方法。
我们试图通过质量设置和视频上传。最终,这个问题的解决方案涉及如何改变post_params。以post_params开头将是下拉列表的默认值:
var selected_quality = $('select#quality-".$dirId." option:selected').val();
...
post_params: {'quality' : selected_quality},
然后,您可以使用addPostParam方法(位于swfupload.js)在下拉列表中选择选项时更新此方法。
$('select#quality-".$dirId."').change(function () {
swfu.addPostParam('quality' , this.value);
});
答案 1 :(得分:0)
########编辑#######
这对你来说很有魅力。
$(function() {
function loader( thing ) {
var settings = {
flash_url : admin_dir + "SWFUpload v2.2.0.1 Samples/demos/swfupload/swfupload.swf",
upload_url: web_root + "pm_admin/upload_image",
post_params: { "aj" : "true", "PR" : thing },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// Button settings
button_image_url: "images/TestImageNoText_65x29.png",
button_width: "95",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">UPLOAD</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
function pre_load(){
var data = '';
data += '<div class="fieldset flash" id="fsUploadProgress">';
data += ' <span class="legend">Upload Queue</span>';
data += '</div>';
data += '<div id="divStatus">0 Files Uploaded</div>';
data += '<div>';
data += ' <span id="spanButtonPlaceHolder"></span>';
data += ' <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />';
data += '</div>';
return data;
}
/* args stores the input/select/textarea/radio's name and then it's value and then passes a single serialised string when uploading */
/* then use a trigger to update the array, off focus, change, keyup... along thos lines on a class set for all inputs, selects and so on... works a treat */
var args = {};
$('.radio').click(function(){
var ob = $(this).siblings('select');
$('#uploader-wrapper').html(pre_load());
$('.radio').siblings('select').attr('disabled', 'disabled');
ob.removeAttr('disabled');
args[$(this).attr('name')] = $(this).val();
args[ob.attr('name')] = $(':selected', ob).text();
loader( $.param(args) );
})
$('select[name=foo]').change(function(){
var ob = $(this);
$('#uploader-wrapper').html(pre_load());
args[ob.attr('name')] = $(':selected', ob).text();
loader( $.param(args) );
});
});
表格:
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p><label>Category: </label><input type="radio" name="for" class="radio" value="category" checked="checked" /><select name="foo"><option>...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<p><label>Product: </label><input type="radio" name="for" class="radio" value="category" /><select disabled="disabled"><option name="foo">...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<div id="uploader-wrapper">
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
</div>
</form>
答案 2 :(得分:0)
我已经用两种方式解决了这个问题(都使用jquery):cookies和mysql。这个概念将是
$('select[name=foo]').change(function(){
$.cookie('dropdown', $(this).val());
});
这样当你更改下拉列表时,你现在有了一个cookie。在upload.php中,您可以调用该cookie并将其用作变量。
另一个选择是
$('select[name=foo]').change(function(){
$.post('updatedatabase.php', {'dropdown': $(this).val()});
});
然后,您将从upload.php调用数据库以获取下拉列表的最后一个值。这两种方式都不是很优雅,但我以前让他们工作过。如果有人发布了更优雅的解决方案,我会很高兴。