When uploading some websites, a dialog box of [Select File] will pop up when you click the browse button. Many times we need to only upload image files, so in the pop-up [Select File] dialog box, only files in the relevant image format are displayed, and the remaining format files are filtered and not displayed.
For example, http://www.youku.com/v1.0.0326/v/swf/up.swf
This is Youku's video upload selection, which is achieved through the FLASH method to not display non-video files.
FLASH to this effect is generally as described here
import flash.net.FileReferenceList;
var fileRef:FileReferenceList = new FileReferenceList();
var allTypes:Array = [];
var Browsing type:Object = new Object();
Browse type.description = Browse type (*.mp3);
Browse type.extension = *.mp3;
allTypes.push(brow type);
fileRef.browse(allTypes);
So can the <input type=File> in our web page also implement pop-up window to limit the file type?
The solution now can only be to remind users that the format of uploading files 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 upload images in JPG or GIF format)
}
</script>
<input type=file name=path onpropertychange=check()> (Only upload images in JPG or GIF format)
<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 FLASH's user experience. It is necessary to follow this type of FLASH upload.