Skip to content

Instantly share code, notes, and snippets.

@joshbuchea
Last active February 19, 2016 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbuchea/a16072d5e1b423096a09 to your computer and use it in GitHub Desktop.
Save joshbuchea/a16072d5e1b423096a09 to your computer and use it in GitHub Desktop.
Canvas Upload
<?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