Drupal 6 Upload Module Reference Warnings

I was testing out a new Drupal project build and found this strange error when uploading files to nodes using the Upload module. This error produced a lot of warning messages that appeared on the screen (in the process alarming my project manager) but appeared to have no impact on the actual function of the module, or the file uploaded. Essentially, when a file was uploaded the following errors were produced.

warning: Parameter 2 to og_user_roles_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to customerror_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to date_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to date_timezone_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to location_node_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to og_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to wysiwyg_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to searchfilter_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.
warning: Parameter 2 to og_access_form_alter() expected to be a reference, value given in \includes\common.inc on line 2892.

Note that this list will vary wildly depending on what modules you have installed.

After doing a bit of searching about on the internet it appears that this is an issue left over from the days of PHP 5.2 and that this error has only started to appear now that I use PHP 5.3 on a regular basis. The problem is that the upload.module passes "array()" as one of the parameters to drupal_alter(), which in turn passes it on to anything that currently hooks into the displayed form. This causes the error to look like it is coming from multiple other modules, rather than upload itself.

The solution is to alter the /modules/upload/upload.module file so that it doesn't pass the array() parameter. This is the code from the upload.module file that causes this error.

  // Render the form for output.
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
    '#tree' => FALSE,
    '#parents' => array(),
  );
  drupal_alter('form', $form, array(), 'upload_js');
  $form_state = array('submitted' => FALSE);
  $form = form_builder('upload_js', $form, $form_state);
  $output = theme('status_messages') . drupal_render($form);

Change this code to be the following, the major change is to the drupal_alter() function call.

  // Render the form for output.
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
    '#tree' => FALSE,
    '#parents' => array(),
  );
  $empty_form_state = array();
  $data = &$form;
  $data['__drupal_alter_by_ref'] = array(&$empty_form_state);
  drupal_alter('form', $data, 'upload_js');
  $form_state = array('submitted' => FALSE);
  $form = form_builder('upload_js', $form, $form_state);
  $output = theme('status_messages') . drupal_render($form);

This is all detailed in the support request on Drupal.org at http://drupal.org/node/925580, along with a patch that will allow to make these changes automatically. It looks from the support request that this didn't make it into Drupal 6.20, but will hopefully make it into the next update.

This problem was recently (January 2011) fixed in the CCK module, and the method used in the patch was initially created to solve the same sort of problem in that module.

Comments

Thanks ...Thanks ...Thanks ...Thanks ...Thanks ...

Permalink

Thanks. It works for me on 6.22

Remains to be seen how to solve my

The selected file blablabla.pdf could not be uploaded. The file is 206.18 kB which would exceed your disk quota of 10 MB.

issue. Anny suggestions or ideas?

Permalink

I think you have exceeded your disk quota, which is 10MB. I would get onto your hosting provider...

Name
Philip Norton
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
2 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.