The hidden file upload input style also verifies the uploaded file format

Source: Internet
Author: User

The first is to hide the file upload input style:

<a class= "link Uploadphoto" href= "#" onclick= "Upload_file.click ()" >

<input type= "File" class= "Form-control" id= "Upload_file" name= "Upload_file" style= "Display:none;" Onchange= "Addpic ();" />

Upload photos </a>

Note: Place the INPUT element in the middle of any other element, formatted as style= "Display:none;" Hidden, while the outside element sets the onclick (onclick= "Upload_file.click ()") event,

When the outside element is clicked to trigger the click event of input, the rest is on the outside

The elements to beautify the process!

Here is the verification of the uploaded file:

function Addpic () {
var objfile = document.getElementById ("Upload_file");

Focus here, you can get the uploaded files;
var file=objfile.files[0];
var name=file.name.tolowercase ();
alert (name);
if (Name.indexof (". png") >-1 | | name.indexof (". gif") >-1
|| Name.indexof (". jpg") >-1) {
You can use Ajax for photo Echo
} else {
$.ligerdialog.warn ("Please select *png,*gif,*jpg type picture!");
}
};

The hidden file upload input style also verifies the uploaded file format

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.