Saving image in byte array in php

how to save image file to byte array. I am sending the image file to the server as base64. and convert to jpg. but i don't know how to convert to bytearray from jpg

$base=$_POST["image"]; $binary=base64_decode($base); $file = fopen("image.jpg", "w"); fwrite($file, $binary); fclose($file); 
+4
source share
2 answers

You need to open the file in binary mode ...

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

Try the imagecreatefromstring() function: http://us.php.net/manual/en/function.imagecreatefromstring.php

(the example on this page is very similar to your code)

0
source

Source: https://habr.com/ru/post/1412326/


All Articles