E
E
EVOSandru62016-02-03 17:29:32
PHP
EVOSandru6, 2016-02-03 17:29:32

How to convert an image to a byte array?

As follows, I accept the file in the controller and save the picture without problems.

Controller:

$img = $_POST['imgBase64'];
echo base64_decode($img);
$img = str_replace('data:image/png;base64,', '', $img);
$img    = str_replace(' ', '+', $img);
$data   = base64_decode($img);
$file = "tmp/".md5(microtime()).".png";
$success = file_put_contents($file, $data);

Before that, I grab a picture from html5 canvas and form it for data in Jquery Ajax as follows: ... post ajax .... I'm wondering how you can form and send to the handler - a byte array of the picture? In my version, $_POST['imgBase64'] receives a Chupocabra with numbers and English letters.

var dataURL = canvas[0].toDataURL();




Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question