The example in this article describes how the PHP implementation will save the canvas image to the server in HTML5. Share to everyone for your reference. The implementation methods are as follows:
First, the question:
When HTML5 was not popular a few years ago, our project manager asked me to ask the project review experts to sign the tablet electronically with a pen at the end of the review. This requires us to review the software to provide such a function: Open the browser, login, enter the review comments page, the bottom of the page there is a block area, the user here with a stylus to sign, and then this signature will be maintained on the server.
Such a demand at that time is let me a lot of trouble, but now think of it, if with HTML5 canvas realize, it is too simple. This is accomplished in the article "putting pictures in HTML5 canvas and saving them as pictures."
Second, the solution:
Previously said a lot of how to save the canvas image as a picture and download the method, but these methods are to save the picture to the client, and our signature requirement is to save canvas content to the server side, how to achieve?
Actually very simple, read the following PHP code, I believe you will also feel very simple.
Copy Code code as follows:
<?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. '
?>
From the Web page uploaded to the server side of the picture is the base64_encode transcoding data URL format, in the server side of the Base64_decode to decode, save into a file.
Perhaps one day you will also need to use it, feel very useful words to collect it!
I hope this article will help you with your PHP program design.