Redactor Upload Image

Hi,

I would like to know anyone know how to use redactor image upload?Is there any example?

Hi,

look at janisto’s ycm module.

He has implemented a nice "universal" (meaning that you can call it for all your models/attribute that are defined as text in your db) way to use redactor with the upload feature.

here is source code.

I just committed easy to use actions for Redactor widget.

Check out https://github.com/janisto/yii-redactor

Modify the actions to your own taste.

Looks good.

Thank you

I’m trying to upload images using this actions from github (https://github.com/janisto/yii-redactor/tree/master/actions)

And a uploads folder is created with the image in it, and in the textarea I’m getting this:

>>>{"filelink":"\/uploads\/file\/content\/d4d8f1c6db38315b1b7cff06e62228cb.png"}

Is this how it should work, or am i missing something ?

Are you using file or image upload action?

How did you configure the controller and view?

Hi janisto

i am using this code in my view(_form)




      $attribute='description';

        Yii::import('ext.imperavi-redactor-widget.ImperaviRedactorWidget');

        $this->widget('ImperaviRedactorWidget', array(

            // You can either use it for model attribute

            'model' => $model,

            'attribute' =>$attribute,

            // or just for input field

          


            'name' => 'description',

            // Some options, see http://imperavi.com/redactor/docs/

            'options' => array(

                'fileUpload' => Yii::app()->createUrl('post/fileUpload', array(

                    'attr' => $attribute,

                )),

                'fileUploadErrorCallback' => new CJavaScriptExpression(

                        'function(obj,json) { alert(json.error); }'

                ),

                'imageUpload' => Yii::app()->createUrl('post/imageUpload', array(

                    'attr' => $attribute,

                )),

                'imageUploadErrorCallback' => new CJavaScriptExpression(

                        'function(obj,json) { alert(json.error); }'

                ),

            ),

        ));

        ?>



and following code in my controller




 public function actions()

    {

        return array(

            

            'fileUpload'=>array(

                'class'=>'ext.imperavi-redactor-widget.ImperaviRedactorWidget.actions.FileUpload',

                'uploadPath'=>Yii::getPathOfAlias('webroot').'/uploads',

                'uploadUrl'=>Yii::getPathOfAlias('webroot').'/uploads',

                'uploadCreate'=>true,

                'permissions'=>0755,

            ),

            'imageUpload'=>array(

                'class'=>'ext.imperavi-redactor-widget.ImperaviRedactorWidget.actions.ImageUpload',

                'uploadPath'=>Yii::getPathOfAlias('webroot').'/uploads',

                'uploadUrl'=>Yii::getPathOfAlias('webroot').'/uploads',

                'uploadCreate'=>true,

                'permissions'=>0755,

            ),


        );

    }



but i got this error


SyntaxError: JSON.parse: expected property name or ‘}’

return window.JSON.parse( data );

please help me where i m wrong…sorry for my poor English

Hi Amjad,

I have faced the same issue and fixed.

Do you have a folder named "actions" in extensions/imperavi-redactor-widget ?

If not you can download it from the link provided by janisto above

That will fix your issue