Programmatically add a file upload field to all webforms (+more file extensions) I have a set of >100 webforms in my projects.

I need to add an upload field to all webforms in my hook_form_alter().

I guess I need to do something like the following.

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if (strpos($form_id, 'webform_client_form_') === 0) {
    $form['file'] = array(
      '#type' =&gt; 'file',
      '#title' =&gt; t('File'),
      '#weight' =&gt; 50,
    );
  }
}


I need to set as on certain attributes such as:


fieldkey
max upload size
allowed file extensions


How can this be achieved?
In this way (hook_form_alter) you will have this field in existing and next created webforms, and you must have own additional _validate and _submit function to process the $form['file'] field.
Other way, the question is how to add programmatically file upload component to existing webform?
To see structure of webform file component, add manually field file to one existing webform and make your setting from the picture, and see devel output tab (enable devel module). Also you may be interested to see http://api.drupalize.me/api/drupal/function/webform_component_insert/7. Then create update script to loop webforms.