enableCsrfValidation = false; return parent::beforeAction($action); } private function resizeImg($w, $h, $imageAlias,$imageAliasSave){ $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); $size = $img->getSize(); $ratio = $size->getWidth()/$size->getHeight(); $height = $h; $width = round($height * $ratio); $imagine = new Imagine(); $imagine->open($imageAlias) ->resize(new Box($width, $h)) ->save($imageAlias, array('flatten' => false)); Image::crop($imageAlias, $w, $h,[($width/2)-($w/2),0]) ->save(Yii::getAlias($imageAliasSave), ['quality' => 100]); } public function actionDownloadPhoto() { die('here'); $model = new UploadForm(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); $md5_file = md5_file($model->file->tempName); $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); $imageAlias = Yii::getAlias($imgDir.'480x365'.'.'.$model->file->extension); $imageLink = '/storage/'.$md5_file.'/480x365'.'.'.$model->file->extension; if(!is_dir($imgDir)) { mkdir($imgDir, 0777, true); } $model->file->saveAs($imageAlias); $this->resizeImg(480, 365, $imageAlias,$imageAlias); return json_encode(['link'=>$imageLink]); } } }