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