php - 在浏览器中显示 png/image 可以在 localhost 中运行,但不能在 aws 中运行

问题描述

我正在使用此代码在 uuser 网络浏览器上输出文件

header("Content-Type: image/png");
header("Content-disposition: inline; filename=".$file_name.".png;");
echo file_get_contents('data:image/png;base64,'. $file_content);

这在我的 localhost docker 环境中运行良好,但在 EC2 中它显示奇怪的字符(如下图所示)。

enter image description here

我做错了吗?

解决方法

尝试这样做:

<img src='data:image/png;base64,<?php echo base64_encode(file_get_contents($file_name.".png")); ?>'>