从控制器symfony2返回图像 [英] Return Image from Controller symfony2
本文介绍了从控制器symfony2返回图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何从控制器返回一个图像没有任何模板。
我从这个代码开始
pre> $ image =1px.png;
$ file = readfile(/ path / to / my / image / 1px.png);
$ headers = array(
'Content-Type'=>'image / png',
'Content-Disposition'=>'inline; filename ='。 ''');
return new Response($ image,200,$ headers);
但在导航器上我有一个断开的链接(找不到文件...)
解决方案现在你返回文件名作为响应体,并将文件内容写入Content-Disposition的filename属性。
return new Response($ image,200,$ headers);
应为:
return new Response($ file,200,$ headers);
...和...
'Content-Disposition'=> '一致; filename ='。$ file。''');
应为...
'Content-Disposition'=> '一致; filename ='。$ image。''');
对吗?
此问题。
I would like to know how can i return an image from the controller without any template.
I would like to use it for pixel tracking in a newsletter.
I start with this code
$image = "1px.png";
$file = readfile("/path/to/my/image/1px.png");
$headers = array(
'Content-Type' => 'image/png',
'Content-Disposition' => 'inline; filename="'.$file.'"');
return new Response($image, 200, $headers);
But on the navigator i have a broken link (file not found...)
解决方案 Right now you return the filename as response body and write the file-content to the filename property of Content-Disposition.
return new Response($image, 200, $headers);
should be:
return new Response($file, 200, $headers);
... and ...
'Content-Disposition' => 'inline; filename="'.$file.'"');
should be ...
'Content-Disposition' => 'inline; filename="'.$image.'"');
right?
Further take a look at this question.
这篇关于从控制器symfony2返回图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文