2014-10-08 94 views
-1

我在我的控制器(我用的Symfony2)生成圖像,當我跟我的形象回到我的迴應,我得到這個:顯示圖像

HTTP/1.0 200 OK 
Cache-Control: no-cache 
Content-Disposition: inline; filename="" 
Content-Type: image/jpeg 

我需要顯示在圖像我的觀點,但如果我把:

<img src="<?= $response ?>" /> 

瀏覽器顯示404錯誤,如果我用

<?php echo $response; ?> 

我只得到

HTTP/1.0 200 OK 
Cache-Control: no-cache 
Content-Disposition: inline; filename="example.jpg" 
Content-Type: image/jpeg 
Date: Wed, 08 Oct 2014 14:55:24 GMT 
X-Sendfile: 67902 

我想顯示圖像,任何想法?

謝謝!

+0

' 2014-10-08 15:17:27

+0

謝謝Marc,但是我怎樣才能將這個射線二進制數據轉換爲數據 - uri? – user3396420 2014-10-08 15:21:32

+0

http://en.wikipedia.org/wiki/Data_URI_scheme#Format – 2014-10-08 16:25:42

回答

0

可以使用該顯示圖像

在控制器的路由:

/* 
* @Route("/getImage", name="getImage") 
* @Method("GET") 
*/ 
public function testAction(Request $request, $id) 
{ 
    $response = new \Symfony\Component\HttpFoundation\Response(); 
    $response->headers->set('Cache-Control', 'private'); 
    $response->headers->set('Content-type', 'image/jpg'); 
    $response->headers->set('Content-Disposition', 'attachment; filename="example.jpg"');   
    $response->setContent(file_get_contents('example.jpg')); 
    return $response;   

}

在您的樹枝的模板:

<img src="{{path('getImage')}}">