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

Jelle_S’s picture

Status: Active » Fixed

Fixed in the latest dev version. Thanks for the report

sah62’s picture

You're welcome. Thanks for the fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.