在php中保存图像的字节数组

时间:2012-05-14 08:21:32

标签: php bytearray

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

$base=$_POST["image"];

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

2 个答案:

答案 0 :(得分:1)

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

$file = fopen("image.jpg", "wb");

答案 1 :(得分:0)

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

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