Total file size for multiple instances

I have multiple SWFUpload instances on a page and each has it's own file size limit. However, I would like to calculate the total file size for all the instances so that I can control the total limit. Is it possible to return the file size of each instance before the upload begin?

Chee

gyphie's picture

Sure

There is an array called SWFUpload.instances that keeps a reference to all the SWFUPload instances you've created.

You can loop through this array and call "getFile" on each index and get the file size.

Something like this (pseudo code):

var totalFileSize = 0;
var totalFileCount = 0;
for (var instance in SWFUpload.instances) {
var fileIndex = 0;
var file = instance.getFile(fileIndex++);
while (file !== null) {
if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
totalFileCount++;
totalFileSize += file.size;
}
file = instance.getFile(fileIndex++);
}
}