4

how can save an image file into byte array. i post the image file to server as base64. and tehn convert to jpg. but i dont know how can convert to bytearray from JPG

$base=$_POST["image"];

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

2 Answers 2

1

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

$file = fopen("image.jpg", "wb");
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.