首页 php框架

Yii2 返回图片音视频数据流


public function actionTest()
{
    $file = '/path/a.jpg';
    $response = Yii::$app->response;
    $response->headers->set('Content-type', \yii\helpers\FileHelper::getMinmeType($file));
    $response->format = \yii\web\Response::FORMAT_RAW;
    $response->stream = fopen($file, 'r');
    return $response;
}



文章评论