Using HTML5 to implement file upload progress bar

Source: Internet
Author: User
Tags file upload progress bar php file upload

<div id= "File" >      <input type= "file" name= "ver" id= "ver"/>      <font color= "Red" >* (APK, IPA is currently automatically renamed) </font><br/>      <div class= "Progress" ><span class= "Bgpro" ></span>< /div></div>

css<style type= "Text/css" >    div.progress{width:400px;height:20px;border:1px solid blue; Background: #fff;d isplay:none;}    Span.bgpro{display:block;height:20px;background:blue;width:0px;text-align:right;color: #fff; font-Size : 12px;} </style>

JS//Triggering Events$ (' #ver '). Change (function() {      //If you can also use the try        if(typeof  This. Files = = ' undefined ') {alert (' Recommended that you use the IE9 above or Firefox, Google browser upload can be real-time view upload progress! ‘); }        varver = This. files[0]; //get file suffix name        varFixed =/\. [^\.] +$/. EXEC (Ver.name); if(Fixed! = '. apk ' && fixed! = '. IPA ') {alert (' Please upload the correct type of file! ‘); return false; }//Show the progress bar$ (' div.progress '). Show (); Try {            varFD =NewFormData (); }Catch(Error) {alert (' Recommended that you use the IE9 above or Firefox, Google browser upload can be real-time view upload progress! ‘); } fd.append (' Ver ', ver); Try{//get XML Object            varXHR =NewXMLHttpRequest (); }Catch(Error) {alert (' Recommended that you use the IE9 above or Firefox, Google browser upload can be real-time view upload progress! ‘); }//Send AjaxXhr.open (' Post ', ' __url__/uploadfile ',true); Xhr.upload.onprogress=function(EV) {//make progress bar show            varPercent = 0; if(ev.lengthcomputable) {percent= * Ev.loaded/Ev.total; Percent= parsefloat (percent). toFixed (2); $(' Span.bgpro '). CSS (' width ', percent + '% '). HTML (percent + '% '));        }        };    Xhr.send (FD); });

PHP File upload using the TP framework/*version File Upload*/ PublicfunctionUploadFile () {//version Upload            if($_files[' ver ' [' name '] = = ')                $ This->error (' Please upload the version file! ‘); //UploadImport ("ORG.Net.UploadFile"); $upload=NewUploadFile ();//instantiating an upload class$upload->maxsize =-1;//set attachment upload size$upload->allowexts = Array (' apk ', ' IPA ');//set attachment upload type$upload->savepath = C (' _upload_url '). ' version/';//Set Attachments upload directory$upload->saverule = ' uniqid '; $upload->autosub =true; if(! $upload->upload ()) {//Upload error message$ This->error ($uploadgeterrormsg ()); }Else{//upload successfully get upload file information$info = $uploadGetuploadfileinfo (); }            return$info [' ver '] [' savename ']; }

Using HTML5 to implement file upload progress bar

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.