寻求在wordpress插件中使用plupload的帮助(前端,而不是管理员)。
我已经全部使用html5,但如果浏览器不支持html5(即IE),那么理论上它应该切换到flash,silverlight等,但事实并非如此。我已经尝试过将Flash放入运行时,但是它只是初始化(大概是因为浏览器正在尝试,并且失败了,使用html5),过了一会儿,错误是-500。
也许很重要,但是在从AJAX返回后显示上传表单后运行JS。但正如我所说,所有与html5一起工作的可爱,但切换到闪光灯等都没有发生。
所以我认为问题在于它不会回退到闪存等等。
一些代码段跟随文件引用。
我正在加载plupload脚本,如下所示:
wp_enqueue_script('plupload-all');
HTML表单是:
echo '<div class="uploader" id="symposium_activity_uploader" style="display:none">';
echo '<a id="pickfiles" href="#">Attach an image</a>';
echo '<div id="progressbar"></div>';
echo '</div>';
echo '<div id="symposium_filelist" class="cb"></div>';
DOM包含HTML表单时运行的JS是:
// Settings ////////////////////////////////////////////////
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,gears,html4',
flash_swf_url : '/wp-includes/js/plupload/plupload.flash.swf',
silverlight_xap_url : '/wp-includes/js/plupload/plupload.silverlight.xap',
browse_button : 'pickfiles',
max_file_size : '1mb',
urlstream_upload : true,
multipart : true,
multi_selection: false,
resize : {width : 300, height : 300, quality : 90},
container : 'symposium_activity_uploader',
url : '/wp-content/plugins/wp-symposium/ajax/dothisnext.php',
filters : [ {title : "Image files", extensions : "jpg,gif,png"} ]
});
uploader.bind('Init', function(up, params) {
jQuery('#symposium_filelist').html("<div>Current runtime: " + params.runtime + "</div>");
jQuery('#symposium_activity_uploader').show();
});
// Init ////////////////////////////////////////////////////
uploader.init();
// Selected Files //////////////////////////////////////////
uploader.bind('FilesAdded', function(up, files) {
jQuery.each(files, function(i, file) {
jQuery('#symposium_filelist').append('<div class="addedFile" id="' + file.id + '">' + file.name + '</div>');
});
up.refresh();
uploader.start();
});
// Error Alert /////////////////////////////////////////////
uploader.bind('Error', function(up, err) {
alert("Error: " + err.code + ", Message: " + err.message + (err.file ? ", File: " + err.file.name : "") + "");
up.refresh();
});
// Progress bar ////////////////////////////////////////////
uploader.bind('UploadProgress', function(up, file) {
var progressBarValue = up.total.percent;
jQuery('#progressbar').fadeIn().progressbar({
value: progressBarValue
});
jQuery('#progressbar .ui-progressbar-value').html('<span class="progressTooltip">' + up.total.percent + '%</span>');
});
// Close window after upload ///////////////////////////////
uploader.bind('UploadComplete', function() {
jQuery('.uploader').fadeOut('slow');
});
已手动验证flash_swf_url和silverlight_xap_url的路径。
我没有发布接收上传图片的代码,因为它正常工作,上面称为dothisnext.php。
总而言之,我的问题是,虽然html5正在运行,但运行时并没有切换到不支持html5的浏览器的flash,silverlight等。我错过了一个重要的步骤吗?