This article briefly introduces the implementation code of adding an upload progress bar to JavaScript swfupload. In fact, the solution is very simple. setStatus (\ "Uploading... \ "); Replace with progress. setStatus (\ "uploading (\" + percent + \ "%) Please wait... \ ");
Code
The Code is as follows: |
Copy code |
Function uploadProgress (file, bytesLoaded ){ Try { Var percent = Math. ceil (bytesLoaded/file. size) * 100 ); Var progress = new FileProgress (file, this. customSettings. upload_target ); Progress. setProgress (percent ); If (percent = 100 ){ Progress. setStatus ("File Uploaded successfully "); Progress. toggleCancel (false, this ); } Else { Progress. setStatus ("uploading (" + percent + "%) Please wait ..."); Progress. toggleCancel (true, this ); } } Catch (ex ){ This. debug (ex ); } } |
Another method
Upload progress setting event
The Code is as follows: |
Copy code |
Function uploadProgress (file, bytesLoaded ){ Try { Var percent = Math. ceil (bytesLoaded/file. size) * 100 ); Var progress = new FileProgress (file, this. customSettings. upload_target ); Progress. setProgress (percent ); If (percent = 100 ){ Progress. setStatus ("the upload is complete and the memory is being released. please lock the mouse and do not touch it. Saving ......"); Progress. toggleCancel (false, this ); // Jump to the uploaded webpage Refresh (); } // Display the upload information Else { Progress. setStatus ("Uploading ...... ‖ uploaded: "+ (bytesLoaded/(1024*1024) +"/"+ file. size + "" + percent + "% 』"); Progress. toggleCancel (true, this ); } } Catch (ex ){ This. debug (ex ); } } |