计算进度条百分比
我正在构建一个文件上传进度条。目前我有一个上传表单,它返回当前上传的数据量。因此,它从零开始,并以位为单位返回当前大小,但我已将其转换为字节。
如果我可以在上传之前获取总文件大小,并且可以获取当前上传的数量,并动态返回它,那么我如何计算它以便我可以使用 1-100% 的 css 宽度值?
我正在使用 swfupload jquery 插件: http://blogs .bigfish.tv/adam/2009/06/14/swfupload-jquery-plugin
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上传百分比=100/文件大小*上传字节数
请记住对两种大小使用相同的单位。
问候
Percents uploaded=100/file size*bytes uploaded
remember to use the same units for both sizes.
Regards
假设进度条(DIV?)的 CSS 最大宽度是 770px。将此称为 PROGRESS_MAX。
如果文件大小(以字节为单位)为 FILE_SIZE,上传的字节数为 UPLOADED_BYTES,则当前进度值(宽度以 px 为单位)为 UPLOADED_BYTES / FILE_SIZE * PROGRESS_MAX
希望这就是您要查找的内容。
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.