3

寻求在 wordpress 插件中使用 plupload 的帮助(前端,而不是管理员)。

我已经全部使用 html5,但是如果浏览器不支持 html5(即 IE),那么理论上它应该切换到 flash、silverlight 等,但事实并非如此。我曾尝试将 Flash 放入运行时,但它只是无法初始化(大概是因为浏览器正在尝试使用 html5 并且失败),过了一会儿出现错误 -500。

也许很重要,但是 JS 在上传表单显示在 AJAX 的返回后运行。但正如我所说,一切都与 html5 一起工作,但切换到 flash 等并没有发生。

所以我认为问题在于为什么它不回退到闪存等。

一些代码片段后跟文件引用。

我正在加载 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 等。我错过了重要的一步吗?

4

0 回答 0