Hi,
I try uploading an image like this :
model Article :
public $image
public function rules()
{
return array(
...
array('image', 'file', 'types'=>'jpg, ,jpeg, gif, png', 'maxSize'=>1024*1024*1, 'tooLarge'=>'File has to be smaller than 1MB'),
array('categoryId, title, description, content, url, tags, writer', 'safe', 'on'=>'search'),
);
}
View _form :
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'article-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
...
<div class="row">
<?php echo $form->labelEx($model,'image'); ?>
<?php echo CHtml::activeFileField($model, 'image'); ?>
<?php echo $form->error($model,'image'); ?>
</div>
Controller ArticleController :
public function actionCreate()
{
$this->layout='//layouts/adminColumn2';
$model=new Article;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Article']))
{
$model->attributes=$_POST['Article'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
{
$model->image->saveAs(Yii::app()->basePath.'/images/');
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('create',array(
'model'=>$model,
));
}
The rules work correctly, the whole form too. The name of the image is correctly added to the DataBase, the path of the “saveAs” function is correct, I have no errors, but the file won’t upload to my images folder …
Thanks in advance for your help