Home  >  Article  >  Web Front-end  >  Research on the Input Button Function of Type File_HTML/Xhtml_Web Page Production

Research on the Input Button Function of Type File_HTML/Xhtml_Web Page Production

WBOY
WBOYOriginal
2016-05-16 16:46:041475browse

When uploading to some websites, a [Select File] dialog box will pop up after clicking the "Browse" button. Many times we need to upload only image files, so in the pop-up [Select File] dialog box, only files in related image formats are displayed, and other 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 option, which uses FLASH to prevent non-video files from being displayed.
The effect achieved by FLASH is generally as described here.
import flash.net.FileReferenceList;
var fileRef:FileReferenceList = new FileReferenceList();
var allTypes:Array = [];
var browse type:Object = new Object();
Browse type.description = "Browse type (*.mp3)";
Browse type.extension = "*.mp3";
allTypes.push(browse type);
fileRef.browse(allTypes) ;
So can we also implement pop-up window restrictions on file types in our web pages?
The current solution is to use monitoring to remind users that the format of the uploaded file is incorrect.


(Only images in JPG or GIF format can be uploaded)


<script><br />function check(){<br />var filepath=path.value<br />filepath=filepath.substring(filepath.lastIndexOf('.') 1,filepath.length)<br />if(filepath != 'jpg' && filepath != 'gif')<br />alert("只能上传JPG或GIF格式的图片")<br />}<br /></script> <script><br />function ck(obj){if(obj.value.length>0){<br />var af="jpg,gif,png,zip,rar,txt,htm";<br />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')};<br />}}<br /></script>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.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn