HTML5 File Upload Preview

Source: Internet
Author: User

function Draguploadfile (d) {this.dom = document.getElementById (d);//drag Dom this. FileType; Upload file type limit this. filetypenomsg; Upload file limit description this.imgcallback; Gets the file success callback method for this. Ajaxpath; File upload path this. Ajaxcallback;    File Upload Completion callback method//Block Browser default event Document.addeventlistener ("DragLeave", function (e) {e.preventdefault ();    }, False);    Document.addeventlistener ("Drop", function (e) {e.preventdefault ();    }, False);    Document.addeventlistener ("DragEnter", function (e) {e.preventdefault ();    }, False);    Document.addeventlistener ("DragOver", function (e) {e.preventdefault (); }, False);}    Set complete load binding DragUploadFile.prototype.Load = function () {var dom = This.dom; var FileType = this.    FileType; var filetypenomsg = this.    filetypenomsg; var Callback = this.    Callback; var Ajaxpath = this.    Ajaxpath;    var imgcallback = This.imgcallback; var ajaxcallback = this.    Ajaxcallback;   Dom.addeventlistener ("Drop", Function (e) {e.preventdefault (); var fileList = e.datatransfer.files; Get the file list if (Filelist.length = = 0) {return;//no file returned} var ifile; File object//Check file type if (FileType! = null) {if (Filelist[0].type.indexof (FileType) >-1) {
IFile = Window.webkiturl?window.webkiturl.createobjecturl (filelist[0]): window. Url.createobjecturl (Filelist[0]); } else {alert (filetypenomsg); Return }} if (Imgcallback! = null) {imgcallback (ifile); } if (Ajaxpath! = null) {//uploads Upajax = new XMLHttpRequest (); Upajax.open ("Post", Ajaxpath, True); Upajax.setrequestheader ("X-requested-with", "XMLHttpRequest"); var postdata = new FormData (); Postdata.append ("Pic", filelist[0]); Upajax.send (PostData); Upajax.onreadystatechange = function () {if (Upajax.status = = && Upajax.readystate = = 4) {//complete return data var retvla = Upajax.responsetext; Eval (retf + "('" +retvla+ "')"); Ajaxcallback (RETVLA); }}}}, False);} Call//define variable box Idvar drag = new Draguploadfile ("drag");//Set Receive file type, and error prompt can not be set, default to all type drag. Filetype= "video";d Rag. filetypenomsg= "Please upload video";d rag.imgcallback=function (file) {};//settings get to the file callback method//drag. Ajaxpath= "/default/upfile";//Set Ajax file upload address//drag. Ajaxpath=function (data) {alert (data)};//Set upload callback method//Set up, load drag. Load ();

In the drop event, because this point has changed, the property has been declared again .... I'll write it again later.

HTML5 File Upload Preview

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.