PHP implements the method of saving Canvas images in HTML5 to the server, html5canvas. PHP implements how to save Canvas images in HTML5 to the server. html5canvas this article describes how to save Canvas images in HTML5 to the server in PHP. I would like to share with you how to use PHP to save the Canvas image in HTML5 to the server, html5canvas
This example describes how to save the Canvas image in HTML5 to the server in PHP. Share it with you for your reference. The specific implementation method is as follows:
I. problems:
When HTML5 was not popular a few years ago, our project manager once asked me to ask the project review experts to use a pen to electronically sign the tablet at the end of the review. This requires the review software to provide such a function: open a browser, log on, enter the review comments page, there is a square area at the bottom of the page, the user is here to sign with a touch pen, then the signature will be kept on the server.
Such a demand turned me around for a long time, but now I think it would be too easy to use html5 canvas. This function is implemented in the article "how to put an image in HTML5 Canvas and save it as an image.
II. solution:
I have mentioned many ways to save a canvas image as an image and download it. However, these methods are used to save the image to the client, our signature requirement is to save the canvas content to the server. how can this problem be achieved?
In fact, it is very simple. after reading the following PHP code, I believe you will also think it is very simple.
The code is 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 .';
?>
An image uploaded from a webpage to a server is in the base64_encode-transcoded Data URL format. The Data is decoded on the server using base64_decode and saved as a file.
You may need to use it one day. if you find it useful, add it to your favorites!
I hope this article will help you with PHP programming.
Examples in this article describes how PHP can save Canvas images in HTML5 to the server. I will share it with you for your reference...