Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AJAX:
- var dataURL = canvas.toDataURL("image/png");
- var request = jQuery.ajax({
- type: "POST",
- url: "http://localhost/fluxor/wp-content/themes/virtue/send-desenho.php",
- data: {
- base64Data: dataURL
- }
- });
- request.done(function (response) {
- alert("Data posted to server!");
- });
- request.fail(function () {
- alert("Failed to send data to server!");
- });
- PHP:
- <?php
- $UPLOAD_DIR = 'assets/img/desenhos/';
- $URLASSETS = 'http://localhost/fluxor/wp-content/themes/virtue/assets/img/desenhos/';
- $img = $_POST['data'];
- $img = str_replace('data:image/png;base64,', '', $img);
- $img = str_replace(' ', '+', $img);
- $data = base64_decode($img);
- $filename = uniqid() . '.png';
- $file = $UPLOAD_DIR . $filename;
- $success = file_put_contents($file, $data);
- //print $success ? $file : 'Unable to save the file.';
- // recipients
- $to = "rkraw22@gmail.com";
- // subject
- $subject = 'Test';
- // message
- $message = '
- <html>
- <head>
- <title>Test</title>
- </head>
- <body>
- <img src="'.$URL.$filename.'"/>
- </body>
- </html>
- ';
- // To send HTML mail, the Content-type header must be set
- $headers = 'MIME-Version: 1.0' . "\r\n";
- $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
- // Mail it
- mail($to, $subject, $message, $headers);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement