我正在尝试上传文件。当我上传小于2mb的文件时,它没问题。但是,当我尝试超过2mb时,我会遇到致命的错误:
Call to a member function saveAs() on null
顺便说一句,表单中的验证是成功的:规则运作良好。
有我的模特课:
class UploadForm extends Model
{
/**
* @var UploadedFile
*/
public $xmlFile;
public function rules()
{
return [
[['xmlFile'], 'file', 'maxSize' => 20480000, 'tooBig' => "Limit is 20mb"],
];
}
public function upload()
{
if ($this->validate()) {
$this->xmlFile->saveAs('uploads/xml/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension);
return true;
} else {
return false;
}
}
}
这是我的表格:
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
<?= $form->field($model, 'xmlFile')->fileInput() ?>
<button>Submit</button>
<?php ActiveForm::end() ?>
我的行动:
if (Yii::$app->request->isPost) {
$model->xmlFile = UploadedFile::getInstance($model, 'xmlFile');
if ($model->upload()) {
//$import->import($model);
return $this->render('upload', ['model' => $model, 'message' => "Success"]);
}
}
答案 0 :(得分:2)
您的php.ini
文件中的问题似乎有限。默认情况下,它们设置为2mb。检查参数upload_max_filesize
和post_max_size