Research on the Input Button Function of Type File

Research on the Input Button Function of Type File
<br />When uploading on some websites, a [Select File] dialog box will pop up after clicking the "Browse" button. Many times we need to upload only image files, then in the pop-up [Select File] dialog box only files of related image formats are displayed, and all other formats of files are filtered out and not displayed.
For example, http://www.youku.com/v1.0.0326/v/swf/up.swf
This is Youku's video upload option, which uses the FLASH method to prevent non-video files from being displayed.
FLASH to this effect is generally as described here
import flash.net.FileReferenceList;
var fileRef:FileReferenceList = new FileReferenceList();
var allTypes:Array = [];
var browse type:Object = new Object();
Browsing type.description = "Browsing type (*.mp3)";
Browse type.extension = "*.mp3";
allTypes.push(browse type);
fileRef.browse(allTypes);
So for the <input type="File"> in our web page, can we also implement a pop-up window to limit the file type?
The current solution is to remind users that the format of the uploaded file is incorrect through monitoring.
<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 format images can be uploaded")
}
</script>
<input type=file name=path onpropertychange="check()"> (Only JPG or GIF format 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().execCommand('delete')};
}}
</script>
<form>
<input type=file name=path onpropertychange="ck(this)"/></form>
However, this effect is obviously not as good as the user experience of FLASH. It is necessary to pay attention to this type of FLASH upload.

<<:  Detailed explanation of DOM style setting in four react components

>>:  MYSQL string forced conversion method example

Recommend

Limiting the number of short-term accesses to a certain IP based on Nginx

How to set a limit on the number of visits to a c...

MySQL 8.0.18 installation and configuration graphic tutorial

Learning objectives: Learn to use Windows system ...

JavaScript to achieve a simple countdown effect

This article example shares the specific code of ...

Vue uses custom instructions to add watermarks to the bottom of the page

Project Scenario Add a custom watermark to the en...

Full steps to create a password generator using Node.js

Table of contents 1. Preparation 2. Writing comma...

MySQL 8.0.18 installation tutorial under Windows (illustration)

Download Download address: https://dev.mysql.com/...

CSS3 overflow property explained

1. Overflow Overflow is overflow (container). Whe...

Dockerfile implementation code when starting two processes in a docker container

I want to make a docker for cron scheduled tasks ...

React antd realizes dynamic increase and decrease of form

I encountered a pitfall when writing dynamic form...

Tomcat+Mysql high concurrency configuration optimization explanation

1.Tomcat Optimization Configuration (1) Change To...

How to improve MySQL Limit query performance

In MySQL database operations, we always hope to a...

Detailed explanation of how to dynamically set the browser title in Vue

Table of contents nonsense text The first router/...

Detailed explanation of the usage of compose function and pipe function in JS

Table of contents compose function Array.prototyp...

Pure CSS to achieve the list pull-down effect in the page

You may often see the following effect: That’s ri...