Codeigniter + Redactor (wysiwyg js editor). Image uploading

☆樱花仙子☆ 提交于 2019-12-12 04:35:13

问题


I trying to integrate wysiwyg editor Redactor in Codeigniter website.

RedactorOptions:

{
    lang: lang(),
    toolbarFixed: true,
    buttons: ['html', '|', 'bold', 'italic', 'deleted', '|', 'image', 'video', '|', 'unorderedlist', 'orderedlist', '|', 'alignment', '|', 'horizontalrule', '|', 'table', '|', 'mtLink'],
    imageUpload: '/upload_photo'
}

while I start to send photo through Upload Image Dialog, I see in Developer console:

Uncaught TypeError: Cannot read property '0' of null redactor.js:1
Redactor.(anonymous function).$.(anonymous function).(anonymous function).uploadLoaded redactor.js:1
p.isFunction.f jquery.js:2
p.event.dispatch jquery.js:2
g.handle.h

Script "upload_photo" is running, but $_FILES is empty.

What wrong and how I can to fix it?

Thank in advance.


回答1:


I have been fumbling around all night trying to fix this same issue, and it turns out to be a simple over site (so give your self a slap like I gave my self one!)

You have CI Cross-site request forgery (CSRF) protection set to TRUE in your config. Redactor is getting that nasty error page you see when you submit a form with out refreshing an old page (I really want to find a fix for that)!

The CSRF token has to be passed in any form that is submitted by POST. This gets done automatically when using CI's form_open(), but Redactor is using it's own form to do the post. So you need to include the CSRF info like this.

uploadFields: {
 <?php echo $this->security->get_csrf_token_name(); ?>: '<?php echo $this->security->get_csrf_hash(); ?>'
 }

I'm pretty sure that's your problem. It was mine (thumps self in head - again).




回答2:


CI's file upload class will look for POST data from input field named 'userfile' by default. The file input field of redactor is named 'file'. So you need to stipulate this name in your upload script by changing $this->upload->do_upload() to $this->upload->do_upload('file').

If this isn't the problem you will need to include your upload code here so I can see what's going on.



来源:https://stackoverflow.com/questions/19143112/codeigniter-redactor-wysiwyg-js-editor-image-uploading

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