PHP Implementation Paste screenshots and complete the Upload function _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.