Php Yii文件上传给控制器中的空数组
您好,请检查我的以下代码: 型号:Php Yii文件上传给控制器中的空数组,php,file-upload,yii,Php,File Upload,Yii,您好,请检查我的以下代码: 型号: public $image; /** * @return string the associated database table name */ public function tableName() { return 'file'; } /** * @return array validation rules for model attributes. */ public function rules() { // NOTE:
public $image;
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'file';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('image_url', 'required'),
array('image_url', 'length', 'max'=>256),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('image_url', 'safe', 'on'=>'search'),
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}
public function actionCreate()
{
$model=new File;
print_r($_POST['File']);
$this->render('create',array(
'model'=>$model,
));
}
<?php
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
);
echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image');
echo $form->error($model, 'image');
echo CHtml::submitButton('Submit');
$this->endWidget();?>
控制器:
public $image;
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'file';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('image_url', 'required'),
array('image_url', 'length', 'max'=>256),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('image_url', 'safe', 'on'=>'search'),
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}
public function actionCreate()
{
$model=new File;
print_r($_POST['File']);
$this->render('create',array(
'model'=>$model,
));
}
<?php
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
);
echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image');
echo $form->error($model, 'image');
echo CHtml::submitButton('Submit');
$this->endWidget();?>
查看:
public $image;
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'file';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('image_url', 'required'),
array('image_url', 'length', 'max'=>256),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('image_url', 'safe', 'on'=>'search'),
array('image', 'file', 'types'=>'jpg, gif, png'),
);
}
public function actionCreate()
{
$model=new File;
print_r($_POST['File']);
$this->render('create',array(
'model'=>$model,
));
}
<?php
$form = $this->beginWidget(
'CActiveForm',
array(
'id' => 'upload-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)
);
echo $form->labelEx($model, 'image');
echo $form->fileField($model, 'image');
echo $form->error($model, 'image');
echo CHtml::submitButton('Submit');
$this->endWidget();?>