【发布时间】:2016-03-12 09:51:27
【问题描述】:
我试图在我自己的https php proxy 中显示不安全的远程图像,以避免ssl 混合模式消息。
不幸的是,下面的代码没有显示图像,我不明白为什么。
<?php
// get productid
$productid = $id;
// get product
$get_product = database::query("SELECT p.image as productimage FROM product p WHERE p.id = '$productid' ORDER BY p.id DESC LIMIT 0, 1");
$product = database::fetch_array($get_product);
$productimage = $product['productimage'];
// get image info
$imginfo = getimagesize($productimage);
// set header according to image type
header("Content-type: $imginfo[mime]");
// display image
readfile($productimage);
die();
?>
我也尝试了file_get_contents($productimage) 而不是 readfile 但两种解决方案都不显示任何图像,只是一个空方块。
知道如何解决这个问题吗?
【问题讨论】:
-
尝试使用 Fiddler 并查看实际返回的内容...
-
HTTP/1.1 200 OK 日期:2016 年 3 月 12 日星期六 10:42:39 GMT 服务器:Apache/2.4.18 (Unix) OpenSSL/1.0.2g PHP/5.3.26 X-Powered- By: PHP/5.3.26 Content-Length: 3 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: image/jpeg
-
“readfile”本身是否成功?试试看它的返回值...
-
我如何验证这一点?
-
根据文档 readfile() 返回已读取的字节数,如果失败则返回 FALSE。您可以尝试将其返回值回显,或者将 file_put_contents() 回显到某个临时文件中...