Upload a file with xheditor

Hi,

I want to upload a file using the xheditor, so i added this in the view:





<?php  $this->widget('application.extensions.xheditor.JXHEditor', array(

    	'model'=>$model,

    	'attribute'=>'image',

        'options'=>array(

        'id'=>'xh1',

        'name'=>'xh',

        'tools'=>'simple', // mini, simple, full or from XHeditor::$_tools

        'width'=>'100%',

        'skin'=>'o2007silver',

        'emot'=>'msn',

	'upImgUrl'=> 'create' // the action name in the controller

            //see XHeditor::$_configurableAttributes for more

          ),

    	'htmlOptions'=>array('cols'=>80,'rows'=>20,'style'=>'width: 100%; height: 200px;'),

	));

?>




In my controller i have this:


$model=new Item;

        if(isset($_POST['Item']))

        {

            $model->attributes=$_POST['Item'];

            $model->image=CUploadedFile::getInstance($model,'image');

            if($model->save())

            {

                $model->image->saveAs('./myfiles');

            }

        }

        $this->render('create', array('model'=>$model));

in the model




public $image;

	public function rules()

	{

		return array(

			array('image','file','types'=>'jpg, gif, png'),

		);

	}






but i have this following error: [color="#FF0000"]create upload interface error, return error[/color]: // blank

Do you have an idea how can i solve this problem?

Thanks

No one can help me with this ?? :blink:

I’m new to using xhEditor, but I will hazard a guess as to one part of your problem. The parameter:

   	'upImgUrl'=&gt; 'create'

This parameter requires a URL, so perhaps you’ll need something like:

'upImgUrl'=&gt; &#036;this-&gt;createUrl('create')

best wishes,

Greg

hello

i am also having same problem

if any one can help me to solve this issue





		<?php  $this->widget('application.extensions.xheditor.JXHEditor', array(

        'model'=>$model,

        'attribute'=>'Text',

        'options'=>array(

        'id'=>'xh1',

        'name'=>'xh',

        'tools'=>'simple', // mini, simple, full or from XHeditor::$_tools

        'width'=>'100%',

        'skin'=>'o2007silver',

        'emot'=>'msn',

        'upImgUrl'=> $this->createUrl('/content/upload') // the action name in the controller

            //see XHeditor::$_configurableAttributes for more

          ),

        'htmlOptions'=>array('cols'=>80,'rows'=>20,'style'=>'width: 100%; height: 200px;'),

        ));

?>




Solution:

Controller should return JSON message. Change


$this->render('create', array('model'=>$model));

to


echo json_encode(array('err'=>'','msg'=>'url to uploaded file'));