簡體   English   中英

Outlook無法從yii2控制器操作下載圖片

[英]outlook cannot download pictures from yii2 controller action

我正在發送包含圖像的HTML電子郵件,這些圖像的src屬性是輸出圖像內容的yii2控制器操作的URL。

如果在瀏覽器中打開電子郵件,則會顯示圖像,但我的問題是Outlook無法下載並顯示圖像。

這是我輸出圖像的動作:

public function actionImage($img_name) {
        $filepath = Yii::getAlias('@webroot')."/media/files/$img_name";
        if (file_exists($filepath))
        {
            $mime = \yii\helpers\BaseFileHelper::getMimeType($filepath);

            header('Content-Type: '.$mime);
            header('Content-Disposition: attachment; filename="' . $img_name. '"');
            header('Content-Length: ' . filesize($filepath));

            // Render the file
            readfile($filepath);

            exit(0);
        }
        else
        {
           die('Media Not Found!');
        }
    }

yii2響應中的sendFile函數有助於解決該問題。

這有效,Outlook下載了圖像。

public function actionImage($img_name) {
        $filepath = Yii::getAlias('@webroot')."/media/files/$img_name";
        if (file_exists($filepath))
        {
            $mime = \yii\helpers\BaseFileHelper::getMimeType($filepath);

            \Yii::$app->response->sendFile($filepath);
            \Yii::$app->response->send();

            exit(0);
        }
        else
        {
           die('Media Not Found!');
        }
    }

暫無
暫無

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

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