在Php(zend框架1.x)我打印RAW值data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA....
。並試圖預覽它在PHP - 我怎麼能回顯這個變量爲jpeg
但是,當加載JPEG鏈接其失敗,內容類型:圖像/ HTML而不是圖像/ JPEG。
在PHP中,我將內容類型設置爲image/jpeg,但不適用。如何解決它?
public function getpreviewAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->_response->setHeader('Access-Control-Allow-Origin', '*');
$this->_response->setHeader('Content-Type', 'image/jpeg');
$post = $this->getRequest()->getQuery();
$data = (object) $post;
$this->db = Application_Model_Db::db_load();
$sql = "select *from sh_av_profile where
username='{$data->username}'
limit 1";
$result = $this->db->fetchAll($sql);
if (count($result) > 0) {
//echo "<img src={$result[0]['preview']} />";
echo $result[0]['preview'];
}
exit;
}
JS:
function previewRender() {
var root = $('img');
//root.attr('src',lasturl +"?"+ Date.parse(new Date().toString()));
root.attr('src', 'http://pbx/ajax/getpreview?username=T1');
}
響應頭:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:18844
Content-Type:text/html
Date:Fri, 31 Jan 2014 07:06:14 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=70
Pragma:no-cache
Server:Apache/2.2.22 (Ubuntu)
Vary:Accept-Encoding
X-Powered-By:PHP/5.4.6-1ubuntu1.2
Getpicture中在Zend的src和getpreviewAction?你確定你發佈的方法是被稱爲? –
在調用getpreviewAction()之前是否打印了任何東西?任何響應都會強制發送標題,因此在發送標題之後更改標題將不會執行任何操作(如您在示例中所見)。 – styfle
這是粘貼錯誤。它應該是getpreview並仍然是同樣的問題。 – YumYumYum