flash批量上传不成功问题及解法集锦

        最近项目里涉及flash插件的批量上传,期间碰到不少问题,经过一番调研都一一解开,这里便记录下。


        在项目根目录添加crossdomain.xml,里面加上允许访问的域名,主要是为了防止项目的静态文件和主程序文件不是放在一个域名下(如主域名为www.test.com,而静态文件放在static.test.com)。

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="www.test.con" />
<allow-access-from domain="*.test.com" />
</cross-domain-policy>

        在火狐浏览器下,使用flash的批量上传失败,是由于session失效的缘故,而项目大多在入口做了是否登录的判断,没有session便进不去上传文件的方法,因此上传失败。解法为在批量上传的调用js里加上当前的session_id,在项目入口处加上相应的判断。


// swfupload插件批量上传
window.onload = function () {
    swfu = new SWFUpload({
        upload_url: "<if condition='C("upload_type") == "upyun"'>http://v0.api.upyun.com/{$bucket}/<else /><php> echo C('site_url');</php>{:U('Upyun/upload',array('imgfrom'=>'photo_list'))}</if>",
        post_params: {"PHPSESSID": "<?php echo session_id();?>",
        file_size_limit : "300kb",
        file_types : "*.jpg;*.png;*.gif;*.bmp",
        file_types_description : "JPG Images",
        file_upload_limit : "{$countpic}",
        file_queue_error_handler : fileQueueError,
        file_dialog_complete_handler : fileDialogComplete,
        upload_progress_handler : uploadProgress,
        upload_error_handler : uploadError,
        upload_success_handler : uploadSuccess,
        upload_complete_handler : uploadComplete,
        button_image_url : "__PUBLIC__/static/swfupload/images/upload.png",
        button_placeholder_id : "spanButtonPlaceholder",
        button_width: 89,
        button_height: 38,
        button_text : '',
        button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;}',
        button_text_top_padding: 0,
        button_text_left_padding: 0,
        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_cursor: SWFUpload.CURSOR.HAND,			
        flash_url : "__PUBLIC__/static/swfupload/swf/swfupload.swf",
        custom_settings : {
            upload_target : "divFileProgressContainer"
        },
        debug: false
    });
};

// KindEditor批量上传图片
var editor;
KindEditor.ready(function(K) {
    editor = K.create('#info', {
        resizeType : 1,
        allowPreviewEmoticons : false,
        allowImageUpload : true,
        uploadJson : '{:C("site_url")}/index.php?g=User&m=Upyun&a=kindedtiropic&PHPSESSID='+"<?php echo session_id();?>",
        items : [
                    'source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'plainpaste', 'wordpaste', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'multiimage','link', 'music', 'video'
                    ]
    });
});

// 后台判断用户是否登录处
if (isset($_SESSION['uid']) || isset($_REQUEST['PHPSESSID'])) {
    if (isset($_REQUEST['PHPSESSID'])) {
        session_id($_REQUEST['PHPSESSID']);
    }
} else {
    $this->redirect('Home/Index/login');
}



你可能感兴趣的:(flash批量上传不成功问题及解法集锦)