0

我想在 php 中创建一个图像,将数据编码为 base64 使用代码:file_put_contents('export/MyFile.png', base64_decode($img)); 我在浏览器上阅读,但 7483 应该是一个更大的数字。如果我打开图像只创建了一半(另一半是透明的),如果变量 $img 包含一个短字符串,它就可以工作。如果它包含一个太长的字符串,则只会部分创建图像。为什么?

PS:如果我使用

$img = base64_decode($img);
$fp = fopen("export/MyFile.png", "w");
fwrite($fp, $img);
fclose($fp); 

我有完全相同的问题

谢谢

4

1 回答 1

1
file_put_contents('export/MyFile.png', base64_decode($img));

应该:

file_put_contents('export/MyFile.png', base64_encode($img));

如果要对图像进行编码,则不能使用 decode 功能。

于 2012-07-10T15:15:51.360 回答