Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I just ran into a division by zero warning when working with a webform that's using multiple file upload:
Warning: Division by zero in _webform_analysis_multifile() (line 678 of /somepath/sites/all/modules/webform_multifile/multifile.inc)
Here's the area of the code that's involved:
$nonblanks = 0;
$sizetotal = 0;
$submissions = 0;
$numfiles = 0;
while ($data = $result->fetchAssoc()) {
if ($fids = unserialize($data['data'])) {
$counter = 0;
foreach (webform_get_multifile($fids) as $file) {
if (isset($file->filesize)) {
$counter++;
$sizetotal += $file->filesize;
}
}
if ($counter) {
$numfiles += $counter;
$nonblanks++;
}
$submissions++;
}
}
$rows[0] = array(t('Left Blank'), ($submissions - $nonblanks));
$rows[1] = array(t('User uploaded file'), $nonblanks);
$rows[2] = array(t('Average uploaded files'), $numfiles / $nonblanks); // <-- Division by zero on this line.
$rows[3] = array(t('Average uploaded file size'), ($sizetotal != 0 ? (int) (($sizetotal/$numfiles)/1024) . ' KB' : '0'));
return $rows;
I ran into this after I clicked on the Webform Results Analysis tab for a webform that has no submissions and no uploaded files. A suggested fix:
$rows[2] = array(t('Average uploaded files'), $nonblanks == 0 ? 0 : $numfiles / $nonblanks);
Comments
Comment #1
Jelle_SFixed in the latest dev version. Thanks for the report
Comment #2
sah62 CreditAttribution: sah62 commentedYou're welcome. Thanks for the fix.