I am quite new to Yii and I m having some problems.
I m trying to upload images to the database following the wiki. However, I can t seem to make it work. It always sees that there is nothing being uploaded.
这里是我的模式守则:
public $uploadedFile;
/**
* Saves the name, size, type and data of the uploaded file
*/
public function beforeSave()
{
if($file=CUploadedFile::getInstance($this, uploadedFile ))
{
$this->image_name=$file->name;
$this->image_type=$file->type;
$this->image_size=$file->size;
$this->image=file_get_contents($file->tempName);
}
return parent::beforeSave();
}
Controller for Create:
public function actionCreate()
{
$model=new Subdivision;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST[ Subdivision ]))
{
$model->attributes=$_POST[ Subdivision ];
$model->image = CUploadedFile::getInstance($this, image );
if($model->save())
$this->redirect(array( view , id =>$model->subdivision));
}
$this->render( create ,array(
model =>$model,
));
}
和我的形式守则:
<div class="row">
<?php echo $form->labelEx($model, uploadedFile ); ?>
<?php echo $form->fileField($model, uploadedFile ); ?>
<?php echo $form->error($model, uploadedFile ); ?>
</div>
谁能帮助?