Sum total of upload size for any given record
4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 7, 2013 (RSS)
By dm - February 6, 2013
hi
i am using the following code to add pdf upload file size information to my detail pages
<?php echo round(filesize($upload['filePath']) * .0009765625 * .0009765625, 2).' MB'; ?>
this works great but i was wondering if there is a similiar simple way to give me the sum total size of all uploads for a given record?
many thanks for you help!
e
Hi,
As far as I know, that is currently the best way to get the size of a file.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com
By dm - February 7, 2013
hi greg
this works great to get the filesize of each individual upload within a record, but i was wondering if there is similar code for the total size of all the uploads within a record ie if ten uploads have been uploaded what is the sum total of those ten not just individually if you follow...
cheers!
Sorry, I didn't read the question properly.
The easiest way to get the sum total of your uploads is to loop through them and add the file sizes together:
//This will contain our total file size.
$totalSize = 0;
//Loop through each record and add its file size to the totalSize variable
foreach($blogRecords[0]['uploads'] as $upload) $totalSize += filesize($upload['filePath']);
//Convert to MB
$totalSize = round($totalSize * .0009765625 * .0009765625, 2);
//Display result
echo $totalSize."MB";
You'll need to change the initial variable in the foreach loop to use the variable that contains your array of images.
Thanks!
Greg
PHP Programmer - interactivetools.com