Skip to content

Instantly share code, notes, and snippets.

@webmechanicx
Forked from xjamundx/canvas-upload.php
Created March 18, 2016 20:57
Show Gist options
  • Save webmechanicx/48b230f600e02d0d8797 to your computer and use it in GitHub Desktop.
Save webmechanicx/48b230f600e02d0d8797 to your computer and use it in GitHub Desktop.
php canvas base64 png decoder
<?php
// requires php5
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() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment