How to enable unlimited file size uploads per user [DRUPAL 6]

While Drupal 6 Upload module enables setting an unlimited file upload quota per user, the settings form (admin/settings/uploads) fails at validation when you set a 0 value in the ‘Total file size per user’ variable.

In order to bypass this validation we need to alter the file:

upload.admin.inc

Specifically this is the hacked function:

/**
 * Form API callback to validate the upload settings form.
 */
function upload_admin_settings_validate($form, &$form_state) {
  if (($form_state['values']['upload_max_resolution'] != '0')) {
    if (!preg_match('/^[0-9]+x[0-9]+$/', $form_state['values']['upload_max_resolution'])) {
      form_set_error('upload_max_resolution', t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
    }
  }

  $default_uploadsize = $form_state['values']['upload_uploadsize_default'];
  $default_usersize = $form_state['values']['upload_usersize_default'];

  $exceed_max_msg = t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) .'
';
  $more_info = t("Depending on your server environment, these settings may be changed in the system-wide php.ini file, a php.ini file in your Drupal root directory, in your Drupal site's settings.php file, or in the .htaccess file in your Drupal root directory.");

   if (!is_numeric($default_uploadsize) || ($default_uploadsize < 0)) {     form_set_error('upload_uploadsize_default', t('The %role file size limit must be a number and zero or greater than zero.', array('%role' => t('default'))));
  }

   if (!is_numeric($default_usersize) || ($default_usersize < 0)) {     form_set_error('upload_usersize_default', t('The %role file size limit must be a number and zero or greater than zero.', array('%role' => t('default'))));
  }
  if ($default_uploadsize * 1024 * 1024 > file_upload_max_size()) {
    form_set_error('upload_uploadsize_default', $exceed_max_msg . $more_info);
    $more_info = '';
  }
  // HACKED: Here is where we remove the "less or equal" condition
  if ($default_usersize && $default_uploadsize > $default_usersize) {
    form_set_error('upload_uploadsize_default', t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => t('default'))));
  }

  foreach ($form_state['values']['roles'] as $rid => $role) {
    $uploadsize = $form_state['values']['upload_uploadsize_'. $rid];
    $usersize = $form_state['values']['upload_usersize_'. $rid];

    if (!is_numeric($uploadsize) || ($uploadsize < 0)) {       form_set_error('upload_uploadsize_'. $rid, t('The %role file size limit must be a number and zero or greater than zero.', array('%role' => $role)));
    }
	if (!is_numeric($usersize) || ($usersize < 0)) {       form_set_error('upload_usersize_'. $rid, t('The %role file size limit must be a number and zero or greater than zero.', array('%role' => $role)));    }
    if ($uploadsize * 1024 * 1024 > file_upload_max_size()) {
      form_set_error('upload_uploadsize_'. $rid, $exceed_max_msg . $more_info);
      $more_info = '';
    }
    if ($usersize && $uploadsize > $usersize) {
      form_set_error('upload_uploadsize_'. $rid, t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => $role)));
    }
  }
}

Also available as a patch for the Upload module. I strongly recommend you to backup the module before and roll back to it in case of unexpected behaviours.

Patch tested on most 6.2x Drupal core versions:

upload.admin.inc.patch

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s