CostaRico / yii2-images

Yii2-images - behavior-based module for resizing, storing, caching and attaching images.
160 stars 98 forks source link

Проблемма при передачи через get $dirtyAlias в контроллере ImagesController #97

Open Mirol1988 opened 3 years ago

Mirol1988 commented 3 years ago

public function actionImageByItemAndAlias($item=''/, $dirtyAlias/) { $dirtyAlias = Yii::$app->request->get('dirtyAlias');

    $dotParts = explode('.', $dirtyAlias);
    if(!isset($dotParts[1])){
        throw new \yii\web\HttpException(404, 'Image must have extension');
    }
    $dirtyAlias = $dotParts[0];

    $size = isset(explode('_', $dirtyAlias)[1]) ? explode('_', $dirtyAlias)[1] : false;
    $alias = isset(explode('_', $dirtyAlias)[0]) ? explode('_', $dirtyAlias)[0] : false;
    $image = $this->getModule()->getImage($item, $alias);

    if($image->getExtension() != $dotParts[1]){
        throw new \yii\web\HttpException(404, 'Image not found (extenstion)');
    }

    if($image){
        header('Content-Type: image/jpg');
        echo $image->getContent($size);
    }else{
        throw new \yii\web\HttpException(404, 'There is no images');
    }

}