html5 - Dark image get while saving a png through PHP -
i trying save captured image html5/canvas mobile. using php (symfony2). followed instructions post (how save png image server-side, base64 data source) dark empty image saved instead of captured.
here javascript post code:
var dataurl = canvas.todataurl(); $.ajax({ type: "post", url: "{{ path("personne_photo_capture",{"id":entity.personne.id}) }}", data: { imgbase64: dataurl } }).done(function (msg) { $('#msg').html(msg); }).fail(function (xhr, textstatus, errorthrown) { $('#msg').html(xhr.responsetext); });
and php saving code :
$rawdata = $_post['imgbase64']; if (isset($rawdata)) { $filtereddata = explode('base64,', $rawdata); $data = base64_decode($filtereddata[1]); $filename = "profil.png"; file_put_contents('picts/small/' . $filename, $data); }
first of all, make sure specify datatype on cliente side
datatype: 'text',
on server side replace first 2 statements :
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
for further pointers take loop @ asked question
Comments
Post a Comment