【问题标题】:View Image via controller function with absolue Path Yii1通过具有绝对路径 Yii1 的控制器功能查看图像
【发布时间】:2017-12-08 05:01:58
【问题描述】:

当我在 gridview 中单击缩略图时,我想查看原始图像。

$file =  'http://localhost/myapp/upload/item_original/'.$model->image;
$type = 'image/jpg';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($file));
readfile($file);

我尝试了上面的代码,但没有成功。 然后我尝试了easyimage扩展。

public function actionViewImg($id){
    $model = $this->loadModel($id);
Yii::import('application.extensions.easyimage.EasyImage');
$image = new Image('http://localhost/obhre/upload/item_original/1235.jpg'); //get the image
$image->save('upload/viewimg/1235.jpg');//save it to another folder
echo Yii::app()->easyImage->thumbOf('upload/viewimg/1235.jpg'); //view the image
}

如果我放置相对路径,上面的代码就可以工作。但不能使用绝对路径。 错误是“没有图像”

【问题讨论】:

    标签: php yii


    【解决方案1】:

    这段代码应该可以工作:

    public function actionViewImg($id) 
    {
        $model = $this->loadModel($id);
        $file = 'http://localhost/myapp/upload/item_original/'.$model->image;
    
        header('Content-Type: image/jpg');
        header('Content-Length: '.filesize($file));
        echo file_get_contents($file);
    
        exit;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2012-05-17
      • 1970-01-01
      相关资源
      最近更新 更多