<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