Skip to content Skip to sidebar Skip to footer

How To Save A PNG Image Server-side, From A Base64 Data String Javascript

i have this code, either the ajax isn't transferring the data correctly or my php doesn't work properly. i know the canvass is saving to data png it writes to the page. Is there a

Solution 1:

changed the php to -------->

define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . 'txtimg.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';

which i got from ----->http://j-query.blogspot.com/2011/02/save-base64-encoded-canvas-image-to-png.html

-cheers works awesome :)


Post a Comment for "How To Save A PNG Image Server-side, From A Base64 Data String Javascript"