HTML tutorial: Research on the Input button function of type File

Source: Internet
Author: User

When you upload a file to a website, the Select File Dialog Box is displayed when you click the Browse button. Most of the time, we only need to upload image files. In the pop-up "select file" dialog box, only related image format files are displayed. In addition, all other format files are filtered and not displayed.

Like http://www.youku.com/v1.0.0326/v/swf/up.swf

This is Youku's video upload option. It does not display non-video files through FLASH.

The FLASH effect is generally described here.

Import flash.net. FileReferenceList;
Var fileRef: FileReferenceList = new FileReferenceList ();
Var allTypes: Array = [];
Var browsing type: Object = new Object ();
Browsing type. description = "browsing type (*. mp3 )";
Browsing type. extension = "*. mp3 ";
AllTypes. push (browsing type );
FileRef. browse (allTypes );

Therefore, can we limit the File type in the pop-up window for our webpage <input type = "File">?

The solution is to use monitoring to remind users that the format of uploaded files is incorrect.

<Script>
Function check (){
Var filepath = path. value
Filepath = filepath. substring (filepath. lastIndexOf ('.') + 1, filepath. length)
If (filepath! = 'Jpg '& filepath! = 'Gif ')
Alert ("only JPG or GIF images can be uploaded ")
}
</Script>
<Input type = file name = path onpropertychange = "check ()"> (only JPG or GIF images can be uploaded)

<Script>
Function ck (obj) {if (obj. value. length> 0 ){
Var af = "jpg, gif, png, zip, rar, txt, htm ";
If (eval ("with (obj. value) if (! /"+ Af. split (","). join ("|") + "/ig. test (substring (lastIndexOf ('. ') + 1, length) 1; ") {alert (" Allowed file types: \ n "?af==obj.createtextrange(cmd.exe cCommand ('delete ')};
}}
</Script>
<Form>
<Input type = file name = path onpropertychange = "ck (this)"/> </form>

However, this effect is obviously not as good as the FLASH user experience. It is necessary to pay attention to this type of FLASH upload.

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.