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.
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).
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.