Skip to content

Instantly share code, notes, and snippets.

@addorange
Created June 19, 2013 09:26
Show Gist options
  • Save addorange/5812982 to your computer and use it in GitHub Desktop.
Save addorange/5812982 to your computer and use it in GitHub Desktop.
Copy png from base64 delivery to create an image file
<?php
// Copy png from base64 delivery to create an image file
// 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 . "" . $_POST['type'] . "_" . date("Y-m-d_Hi", time()) . '.png';
$success = file_put_contents($file, $data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment