I need a form to load image on server. model
<?php
class Item extends CFormModel
{
public $image;
public $retro;
public function rules()
{
return array(
array('image', 'file', 'types'=>'jpg, gif, png, eps'),
);
}
}
?>
controller
<?php
class ItemController extends CController
{
public function actionLoad()
{
$model=new Item;
if(isset($_POST['image']))
{
$model->attributes=$_POST['image'];
$model->image=CUploadedFile::getInstance($model,'image');
if($model->save())
{
$model->image->saveAs('images/test');
}
}
$this->render('create', array('model'=>$model));
}
}
?>
and form
<?php echo CHtml::beginForm('','post',array('enctype'=>'multipart/form-data')); ?>
<?php echo CHtml::activeFileField($model, 'image'); ?>
<?php echo CHtml::activeTextField($model, 'retro'); ?>
<?php echo CHtml::submitButton('Create' ); ?>
<?php echo CHtml::endForm(); ?>
this code copied from cookbook and just a little modified but it doesn`t work. strange thing is if i var_dump($_post) value "image" always is empty. what wrong - why image empty?