Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // requires php5
- // https://gist.githubusercontent.com/fazlurr/9802071/raw/894b282b43050cdcee77f7a73413d52390209f51/canvas-upload.php
- 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.';
Advertisement
Add Comment
Please, Sign In to add comment