SHOW:
|
|
- or go back to the newest paste.
1 | AJAX: | |
2 | var dataURL = canvas.toDataURL("image/png"); | |
3 | var request = jQuery.ajax({ | |
4 | type: "POST", | |
5 | url: "http://localhost/fluxor/wp-content/themes/virtue/send-desenho.php", | |
6 | data: { | |
7 | base64Data: dataURL | |
8 | } | |
9 | }); | |
10 | ||
11 | request.done(function (response) { | |
12 | alert("Data posted to server!"); | |
13 | }); | |
14 | ||
15 | request.fail(function () { | |
16 | alert("Failed to send data to server!"); | |
17 | }); | |
18 | ||
19 | ||
20 | PHP: | |
21 | <?php | |
22 | - | // requires php5 |
22 | + | $UPLOAD_DIR = 'assets/img/desenhos/'; |
23 | - | define('UPLOAD_DIR', 'images/'); |
23 | + | $URLASSETS = 'http://localhost/fluxor/wp-content/themes/virtue/assets/img/desenhos/'; |
24 | ||
25 | $img = $_POST['data']; | |
26 | $img = str_replace('data:image/png;base64,', '', $img); | |
27 | $img = str_replace(' ', '+', $img); | |
28 | - | $file = UPLOAD_DIR . uniqid() . '.png'; |
28 | + | |
29 | - | //$success = file_put_contents($file, $data); |
29 | + | $filename = uniqid() . '.png'; |
30 | $file = $UPLOAD_DIR . $filename; | |
31 | $success = file_put_contents($file, $data); | |
32 | //print $success ? $file : 'Unable to save the file.'; | |
33 | ||
34 | // recipients | |
35 | $to = "rkraw22@gmail.com"; | |
36 | ||
37 | // subject | |
38 | $subject = 'Test'; | |
39 | ||
40 | // message | |
41 | $message = ' | |
42 | <html> | |
43 | <head> | |
44 | <title>Test</title> | |
45 | </head> | |
46 | - | <img src="'.$_POST[$file].'"/> |
46 | + | |
47 | ||
48 | <img src="'.$URL.$filename.'"/> | |
49 | ||
50 | </body> | |
51 | </html> | |
52 | '; | |
53 | ||
54 | // To send HTML mail, the Content-type header must be set | |
55 | $headers = 'MIME-Version: 1.0' . "\r\n"; | |
56 | $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; | |
57 | ||
58 | // Mail it | |
59 | mail($to, $subject, $message, $headers); | |
60 | ?> |