【发布时间】:2014-01-31 07:13:49
【问题描述】:
在 Php(zend 框架 1.x)中,我正在打印 RAW 值 data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA.... 。并尝试在
但是当加载 JPEG 作为链接失败时,内容类型:image/html 而不是 image/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
【问题讨论】:
-
在 src 中获取图片并在 zend 中获取预览操作?你确定你发布的方法被调用了吗?
-
在调用
getpreviewAction()之前是否打印了任何内容?任何响应都会强制发送标头,因此在发送标头后更改标头将无济于事(如您在示例中所见)。 -
粘贴错误。它应该是 getpreview 并且仍然是同样的问题。
-
@styfle: 从 _helper 和 _response 没有打印这些是开始
标签: php jquery zend-framework