【发布时间】:2019-03-22 10:30:55
【问题描述】:
我想使用 GET 方法(3 个参数:Key、ImageID、Size)显示来自 php url 的一些远程图像。 例如:http://www.example.com/getImage?Key=thekey&ImageId=2&Size=1
我关注了这个:https://stackoverflow.com/a/12629513(将内容类型替换为 jpeg),尝试使用网络上的随机 jpeg 图像并成功了。
但是,当我使用我的 php url 尝试此方法时:文件已损坏。
<?php
function img_create($filename, $mime_type)
{
$content = file_get_contents($filename);
$base64 = base64_encode($content);
return ('data:' . $mime_type . ';base64,' . $base64);
}
?>
<img src="<?php print img_create('http://www.example.com/getImage?Key=thekey&ImageId=2&Size=1','image/jpeg'); ?>" alt="random logo" />
任何想法..?
【问题讨论】:
-
html 输出是什么?你真的得到一个base64字符串吗?