public function actionFind()
{
$response = Yii::$app->response;
\Yii::$app->response->format = yii\web\Response::FORMAT_RAW;
\Yii::$app->response->headers->add('content-type', 'image/jpg');
$img_url = file_get_contents('images/ab.jpg');
Yii::$app->response->data($img_url);
return \Yii::$app->response;
}
为什么这段代码有错误?
错误是: 无法显示,因为它包含错误
答案 0 :(得分:1)
数据是属性,而不是函数http://www.yiiframework.com/doc-2.0/yii-web-response.html#$data-detail
public function actionFind()
{
$response = \Yii::$app->response;
$response->format = yii\web\Response::FORMAT_RAW;
$response->headers->add('content-type', 'image/jpg');
$img_data = file_get_contents('images/ab.jpg');
$response->data = $img_data;
return $response;
}