Advertisement
Sixem

PHP Save Base64 String As Image

Jun 26th, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.33 KB | None | 0 0
  1. <?php
  2.     define('UPLOAD_DIR', 'images/');
  3.     $image = 'base64stringhere';
  4.     $image = str_replace('data:image/png;base64,', '', $image);
  5.     $image = str_replace(' ', '+', $image);
  6.     $data = base64_decode($image);
  7.     $file = UPLOAD_DIR . uniqid() . '.png';
  8.     $success = file_put_contents($file, $data);
  9.     print $success ? $file : 'error';
  10. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement