Image Upload Duplicate Sql Entry!


When am uploading an image the data is duplicated in the the db, because of saveAs!

	public function actionCreate()


		$model=new Article;






					$MainFileName= uniqid(time(), false);	

					$FileExt = $main_image->getExtensionName();

					$model->main_image = $MainFileName.$FileExt;













What the mistake ?!


What exactly is being duplicated?

What did you mean by saying "because of saveAs"?

Paste the Article model’s code.

What I mean that once am usingCUploadedFile::save as to save the image, the submitted data will goes twice in the db, the yii saving the into the db twice, the image saving is going fine.

CUploadedFile::saveAs is not dealing with db, the problem is somewhere else.

You probably are using an CActiveForm in your update view with some ajax validation enabled. Before you save the form it makes an ajax call to the same action. You don’t check for it and thus it saves the record instead of just validating it. Then you save it again, via normal request (not ajax).

Either disable the ajax validation or add code that intercepts it, there is another field in the POST data called ‘ajax’.

Yes, it was ajax issue in the form ;)

Thanks a lot!