Determine Image Upload, js determine the size of the uploaded Image

Source: Internet
Author: User

Determine Image Upload, js determine the size of the uploaded Image

It is not only the extension to be determined, but also the extension to be modified.

1 private bool IsImage (string filePath) 2 {3 Image image; 4 try 5 {6 image = Image. fromFile (filePath); 7 image. dispose (); 8 return true; 9} 10 catch (Exception ex) 11 {12 return false; 13} 14}View Code

Determine the file header

/// <Summary> /// determine the type of the uploaded file based on the file header /// </summary> /// <param name = "filePath"> filePath is the complete path of the file </param> // <returns> returns true or false </returns> private bool IsPicture (string filePath) {try {FileStream fs = new FileStream (filePath, FileMode. open, FileAccess. read); BinaryReader reader = new BinaryReader (fs); string fileClass; byte buffer; buffer = reader. readByte (); fileClass = buffer. toString (); buffer = reader. readByte (); fileClass + = buffer. toString (); reader. close (); fs. close (); if (fileClass = "255216" | fileClass = "7173" | fileClass = "13780" | fileClass = "6677 ") // 255216 is jpg; 7173 is gif; 6677 is BMP; 13780 is PNG; 7790 is exe; 8297 is rar {return true;} else {return false ;}} catch {return false ;}}View Code

 

Related Article

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.