views:

821

answers:

2

I am building a file upload progress bar. Currently I have an upload form which returns the current amount of uploaded data. So, it starts at zero, and returns the current size in bits, but I have converted that to bytes.

If I can get the total file size before I upload, and can get the current amount uploaded, and return this dynamically, how could I calculate this so that I can use a 1-100% value for a css width?

I am using the swfupload jquery plugin: http://blogs.bigfish.tv/adam/2009/06/14/swfupload-jquery-plugin

A: 

Percents uploaded=100/file size*bytes uploaded

remember to use the same units for both sizes.

Regards

Atmocreations
A: 

Say your CSS maximum width for the progress bar (DIV?) is 770px. Call this PROGRESS_MAX.

If the file size in bytes is FILE_SIZE, and the number of bytes uploaded is UPLOADED_BYTES then the current progress value (width in px) is UPLOADED_BYTES / FILE_SIZE * PROGRESS_MAX

Hope that's what you're looking for.

Bernhard Hofmann
Totally understand. Thank you!
Nic Hubbard