Please Help me
To upload multiple file in to the database for registration
Error: storing the data but the files are not getting uploaded
please help
my code is
[b]
In Form [/b]
<?php $this->widget('CMultiFileUpload',
array(
'model'=>$model,
'attribute' => 'documents',
'accept'=>'jpg|gif|png|doc|docx|pdf',
'denied'=>'Only doc,docx,pdf and txt are allowed',
'max'=>4,
'remove'=>'[x]',
'duplicate'=>'Already Selected',
)
);?>
[b]
In Controller[/b]
public function actionRegistration()
{
$model=new PatientRegistration;
$this->performAjaxValidation($model);
$last_register = PatientRegistration::model()->find(array('order'=>'register_id DESC'));
if ($last_register!=Null)
{
$last_register_number = str_replace("PRN", "", $last_register->patient_id);
$new_register_number = $last_register_number + 00001;
$format=array('integerDigits'=>5,);// will be padded with 0 if not enough digits
$pattern="000000#";
$formated_new_register_number=Yii::app()->numberFormatter->format($pattern, $new_register_number, $currency=NULL);
$model->patient_id= "PRN".$formated_new_register_number;
}else
{
$model->patient_id= "PRN000001";
}
$model->registered_datetime=new CDbExpression('NOW()');
// form inputs are valid, do something here
if(isset($_POST['PatientRegistration']))
{
$model->attributes=$_POST['PatientRegistration'];
if($model->validate())
{
if(isset($_POST['PatientRegistration']))
{
if($filez=$this->uploadMultifile($model,'documents','/Images/'))
{
$model->documents=implode(",", $filez);
}
$model->attributes=$_POST['PatientRegistration'];
if($model->save())
{
// $this->render('registration',array('model'=>$model));
$this->redirect(array('/patientregistration/patientview','id'=>$model->register_id));
}
}
}
}
$this->render('registration',array('model'=>$model));
}
public function uploadMultifile($model,$attr,$path)
{
/*
* path when uploads folder is on site root.
* $path='/uploads/doc/'
*/echo "HELLOOOOOOOOOOOOOOOOOOOOOO";
if($sfile=CUploadedFile::getInstances($model, $attr)){
foreach ($sfile as $i=>$file){
// $formatName=time().$i.'.'.$file->getExtensionName();
$fileName = "{$sfile[$i]}";
$formatName=time().$i.'_'.$fileName;
$file->saveAs(Yii::app()->basePath.$path.$formatName);
$ffile[$i]=$formatName;
}
return ($ffile);
}
}