PHP implementation of Paste and upload function completed
Today found Segmentfault comment message inside can paste upload pictures, so study how to achieve!
The principle is very simple actually is to monitor the paste event, and then detects whether the pasted thing inside has the picture, some words directly triggers the Ajax uploads
Code can be run directly, interested you can try
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
Header ("access-control-allow-origin:*"); $url = ' http://'. $_server[' http_host '; $file = (isset ($_post["file"])? $_post["File"]: '; if ($file) { $data = Base64_decode (Str_replace (' data:image/png;base64, ', ', $file)); Only PNG-formatted images are available, so just work with PNG. $name = MD5 (Time ()). '. png '; The file name is MD5 processed here. File_put_contents ($name, $data); echo "$url/$name"; Die } ?> |
The above mentioned is the whole content of this article, I hope you can like.
http://www.bkjia.com/PHPjc/1000072.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000072.html techarticle PHP Implementation paste and upload functionality found today segmentfault Comment message inside can paste upload pictures, so study how to achieve! The principle is very simple actually is monitoring sticky ...