簡體   English   中英

通過帶有絕對路徑Yii1的控制器功能查看圖像

[英]View Image via controller function with absolue Path Yii1

當我在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
}

如果我把相對路徑而不是絕對路徑,上面的代碼是有效的。 錯誤是“沒有圖像”

此代碼應工作:

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM