4

如何将图像文件保存到字节数组中。我将图像文件作为base64发布到服务器。和tehn转换为jpg。但我不知道如何从 JPG 转换为 bytearray

$base=$_POST["image"];

$binary=base64_decode($base);
$file = fopen("image.jpg", "w");
fwrite($file, $binary);
fclose($file);
4

2 回答 2

1

您需要以二进制模式打开文件...

$file = fopen("image.jpg", "wb");
于 2012-05-14T08:26:12.207 回答
0

试试这个imagecreatefromstring()功能:http ://us.php.net/manual/en/function.imagecreatefromstring.php

(该页面上的示例与您的代码非常相似)

于 2012-05-14T08:26:35.410 回答