解码 base64 图像并将其保存在网络服务器上 - 检索相同的图像并再次编码

Decode base64 image and save it on a webserver - retrieve the same and encode again

我有一张图像,它是从 API 响应中以 base64 字符串形式获得的。最初 - 我将字符串直接保存在数据库中的 mediumtext 字段中。不过好像吃多了space.

有没有一种方法可以将图像保存为平面文件 - 将其 link 存储在数据库中我的图像字段中 - 并再次使用查询检索它?

我在服务器端使用 PHP - 和 AWS。我需要这个,因为我 运行 没有数据库 space。

此外 - 我知道我们可以通过将 base64 字符串解码为图像并将其保存在服务器上来保存 base64 字符串 - 但我如何检索和编码相同的内容?

接受这个,使用对函数 base64_encode/base64_decode:

$encoded = 'SomeBase64EncodedString';

$decoded = base64_decode($encoded);
// Now $decoded is the binary content of image, save it anywhere you want.
// Example: file_put_content('/tmp/image.png', $decoded);

// When you want to retrieve the base64 encoded string again
$decoded = file_get_contents('/tmp/image.png');
$encoded = base64_encode($decoded);

// Now you have $encoded, as a base64 encoded string. Do as you please with it.