XUploadFile

Hi! I use XUploadFile for upload photo to my site and want it to store image url in mysql, but i don’t know to how do this. Can anyone help me with this.

Buddy, I haven’t used Xupload. But this a generic method I use to upload the file and save url in my database.

Your view file


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'ticket-form',

	'enableAjaxValidation'=>true,'htmlOptions'=>array(

        'enctype'=>'multipart/form-data')

)); ?>


<div class="row">

		<?php echo $form->labelEx($model,'image'); ?>

		<?php echo $form->fileField($model,'image'); ?>

		<?php echo $form->error($model,'image'); ?>

	</div>




Then in your controller file. In the create action function. In addition, create a folder called images at /protected/images. All your files will be stored here.


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

		{

			$model->attributes=$_POST[' Whateva value u have here'];

			

			

			//adding image code

			

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

                        $fecha = date('YmdHms');

                        $model->image->saveAs(Yii::app()->basePath.'/images/'.$fecha.'_'.$model->image);

                        $model->image = $fecha.'_'.$model->image;   

			

			//end image code


			

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}

		

		$this->render('create',array(

			'model'=>$model,

		));