ASP. NET upload image, server verification, width, height, file type, size, file size, Image Upload, image format check

Source: Internet
Author: User

First, add

// <Input style = "width: 272px; height: 22px "type =" file "size =" 26 "name =" picfile "id =" picfile "runat =" server ">

CodeAs follows:

// Protected system. Web. UI. htmlcontrols. htmlinputfile picfile;

// Check and upload

private bool checkpic ()
{< br> bool issafe = false;
httppostedfile PIC = picfile. postedfile;
// check the extension
string picext = system. io. path. getextension (picfile. postedfile. filename ). tolower ();
If (picext = ". jpg "| picext = ". GIF "| picext =" BMP "| picext =" PNG ")
{< br> issafe = true;
}< br> else
{< br> issafe = false;
kit. alert (this. page, "the image format is incorrect. Convert the image format to JPG, GIF, BMP, and PNG.");
return issafe;
}< br> // check the image size
If (PIC. contentlength> picmaxlength ()
{< br> issafe = false;
kit. alert (this. page, "exceeds the image size limit");
return issafe;
}< br> // image size check
system. io. stream picstream = pic. inputstream;
system. drawing. image IMG = system. drawing. image. fromstream (picstream);
If (IMG. width> 0 & IMG. height> 0)
{< br> issafe = true;
// Step 3: Verify the ID card image and upload the
saveidcard (txtidcard. text. trim ();

Picstream. Close ();
Picstream. Flush ();
}
Else
{
Issafe = false;
Kit. Alert (this. Page, "invalid image file ");
// Picstream. Close ();
// Picstream. Flush ();
Return issafe;
}

Return issafe;
}

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.