如何将图像文件保存到字节数组中。我将图像文件作为base64发布到服务器。然后转换为jpg。但我不知道如何从JPG转换为字节数组
$base=$_POST["image"];
$binary=base64_decode($base);
$file = fopen("image.jpg", "w");
fwrite($file, $binary);
fclose($file);
答案 0 :(得分:1)
您需要以二进制模式打开文件...
$file = fopen("image.jpg", "wb");
答案 1 :(得分:0)
尝试imagecreatefromstring()
功能:http://us.php.net/manual/en/function.imagecreatefromstring.php
(该页面上的示例与您的代码非常相似)