解决 KindEditor SWFUpload 批量上传检测用户登录状态的问题

依然范特西╮ 提交于 2019-12-01 00:48:12

使用KindEditor时遇到个小问题,在给 【爱玩电脑】 开发 用户发表文章 的功能时,KindEditor 批量上传图片失败。

经过百度搜索发现是 #SWFUpload# 无法读取cookie的原因,既然问题找到了就想办法解决呗。又经过一番百度搜索,找到#KindEditor#官方的解决方法

http://www.kindsoft.net/docs/option.html#extrafileuploadparams

我的解决方法:

var editor;
var editorSets = {

    themeType: 'default',
    urlType: 'absolute',
    cssPath: '/static/editor/iframe.css',

    uploadJson: '/article/add/upload/',
    allowImageUpload: true,
    allowFlashUpload: true,
    allowMediaUpload: true,
    allowFileUpload: true,

    allowFileManager: true,
    fileManagerJson: '/article/add/fileManager/',

    formatUploadUrl: true,
    fillDescAfterUploadImage: true,

    syncType: 'form',

    afterChange: function() {
        this.sync()
    },

    extraFileUploadParams: {
        user_id: '1',
        password: 'f49a77ef44205b1ed45f29'
    }
};

KindEditor.ready(function(K) {
    editor = K.create('#text', editorSets)
})

就是按官方提供的方法,在 editorSet 中添加extraFileUploadParams,我保存了一个user_id和password的密文,这两个参数会在上传文件时传到服务器端,以PHP为例可以使用$_REQUEST['user_id']接收,下面是我服务器端的验证登录代码:

$user_id = isset($_REQUEST['user_id']) ? intval($_REQUEST['user_id']) : 0;
$password = isset($_REQUEST['password']) ? trim($_REQUEST['password']) : '';
$sql = "SELECT * FROM `pcb_user` WHERE `id` = ? LIMIT 1";
$data = $this->mysql->find($sql, array($user_id));
if (!$data || $data['status'] <= 0 || $data['password'] != $password)
    exit('登录用户才可以上传文件');

~完~

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!