Javascript determines the size and format of the uploaded Image

Source: Internet
Author: User
  1. Reference content is as follows:
  2. <! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
  3. <HTML>
  4. <Head>
  5. <Title> new document </title>
  6. <Meta name = "author" content = "Baoyu">
  7. </Head>
  8. <Script language = "JavaScript">
  9. PHP programmer site
  10. <! --
  11. // Check whether the inserted image is an image
  12. VaR IMG = NULL;
  13. Function chkimg (indium)
  14. {
  15. If (IMG) IMG. removenode (true );
  16. IMG = Document. createelement ("IMG ");
  17. IMG. attachevent ("onreadystatechange", isimg );
  18. IMG. attachevent ("onerror", notimg );
  19. IMG. src = indium;
  20. }
  21. Function notimg ()
  22. {
  23. Alert ("You are not inserting an image. Please reselect to insert it ");
  24. }
  25. Function isimg () phperz ~ Com
  26. {
  27. Show. insertadjacentelement ("beforeend", IMG );
  28. Show1.innerhtml = "image size" + IMG. filesize/1024 + "k <br/> image width" + IMG. offsetwidth + "<br/> Image Height" + IMG. offsetheight;
  29. }
  30. // -->
  31. </SCRIPT>
  32. <Body>
  33. <Div id = "show"> </div>
  34. <Div id = "show1"> </div>
  35. <Input type = "file" name = "" onpropertychange = "chkimg (this. Value)"/>
  36. </Body>
  37. </Html>

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.