Hello for all,
How to upload a file in the database ?
That’s my code.
[color="#FF0000"]In controller (creat) :[/color]
$model=new Societes;
if(isset($_POST['Societes']))
{
$model->attributes=$_POST['Societes'];
$model->logo=CUploadedFile::getInstance($model,'Logo');
if($model->save())
$model->logo->saveAs('path/images');
$this->redirect(array('view','id'=>$model->Id));
}
$this->render('create',array(
'model'=>$model,
));
[color="#FF0000"]code of Model :[/color]
public function rules()
{
return array(
array('Nom', 'required'),
array('Nom', 'length', 'max'=>75),
array('Logo', 'file', 'types'=>'jpg, gif, png'),
array('Id, Nom, Logo', 'safe', 'on'=>'search'),
);
}
[color="#FF0000"]and the code of _form for add a new company with the pecture of logo :[/color]
<div>
<?php echo $form->labelEx($model,'Nom'); ?>
<?php echo $form->textField($model,'Nom',array('size'=>40,'maxlength'=>45)); ?>
<?php echo $form->error($model,'Nom'); ?>
</div>
<div>
<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>
<?php echo CHtml::activeFileField($model, 'Logo'); ?>
<?php echo CHtml::endForm(); ?>
</div>
Thanks for all…