Yii2上传的图片没有显示

时间:2019-05-16 17:23:35

标签: php image file-upload yii2

我将this yii2 module用于上传图片。

我的上传文件夹是:

C:\XAMPP\HTDOCS\MYAPPNAME\WEB\UPLOAD
├───cache
├───global
└───store
    └───Products
        └───Product15

其中存储的位置是原始图片的文件夹,而高速缓存则用于调整大小的图片。 yii2-images的配置如下:

'yii2images' => [
            'class' => 'rico\yii2images\Module',
            //be sure, that permissions ok
            //if you cant avoid permission errors you have to create "images" folder in web root manually and set 777 permissions
            'imagesStorePath' => 'upload/store', //path to origin images
            'imagesCachePath' => 'upload/cache', //path to resized copies
            'graphicsLibrary' => 'GD', //but really its better to use 'Imagick'
            'placeHolderPath' => '@webroot/upload/store/no-image.png', // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
],

我的产品模型上传方法是:

public function upload()
    {
        if ($this->validate()) {
            $path = 'upload/store/' . $this->image->baseName . '.' . $this->image->extension;
            $this->image->saveAs($path);
            $this->attachImage($path);
            @unlink($path);
            return true;
        } else {
            return false;
        }
    }

上传图像工作。我的意思是,它们实际上会出现在应有的位置。我加载图片

<?php $img = $model->getImage(); ?>

,并且在我的DetailView小部件中,而不是在“ img”中:

[
                'attribute' => 'image',
                'value' => "<img src='{$img->getUrl()}'>",
                'format' => 'html',
            ],

而不是渲染图像,我得到的是:

image-by-item-and-alias?item=Product15&dirtyAlias=71273544a6-1.jpg

我不知道这个“按项目和别名图像= Product15&dirtyAlias”在哪里?部分甚至来自实际上必须是这样的时间:

Products\Product15\71273544a6-1.jpg

并使用给定格式的html参数,因此它必须呈现图像。

您能指出我这个错误的根源吗?

0 个答案:

没有答案
相关问题