File upload 使用Yii2的UploadedFile扩展名上载较大的图像
我想把图像上传到服务器上,我尝试使用一个代码,我在youtube视频中看到了这个代码 但是,它可以处理轻量级的150KB文件;我正试图上传一个3.1MB的图像,程序中断了。 这是我的代码:File upload 使用Yii2的UploadedFile扩展名上载较大的图像,file-upload,yii,yii2,image-uploading,File Upload,Yii,Yii2,Image Uploading,我想把图像上传到服务器上,我尝试使用一个代码,我在youtube视频中看到了这个代码 但是,它可以处理轻量级的150KB文件;我正试图上传一个3.1MB的图像,程序中断了。 这是我的代码: public function actionCreate() { $model = new Images(); if ($model->load(Yii::$app->request->post())) { $model->file = Upload
public function actionCreate()
{
$model = new Images();
if ($model->load(Yii::$app->request->post())) {
$model->file = UploadedFile::getInstance($model, 'file');
$fileName = $model->category.''.date('U').'.'.$model->file->extension;
// save the path in db
$model->location = '/yii_advance/frontend'.'/web/images/'.$fileName;
$model->file->saveAs(Yii::getAlias('@frontend').'/web/images/'.$fileName);
// crea y guarda el thumbnail de la imagen subida
Image::thumbnail(Yii::getAlias('@frontend').'/web/images/'.$fileName, 220, 120)
->save(Yii::getAlias('@frontend').'/web/images/thumbs/'.$fileName, ['quality' => 80]);
$model->thumbLocation = '/yii_advance/frontend'.'/web/images/thumbs/'.$fileName;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
有人能帮我吗
注:
我已经在没有缩略图的情况下进行了测试,我认为解决方案可以是一种在完成上传后运行$model->save和return的方法。好的,正如user1852788所说,解决方案在我的php.ini文件中。 我不得不更改upload_max_filesize属性的限制为2M 谢谢。检查您的php.ini文件,以获取上传\u max\u文件大小和发布\u max\u文件大小指令