1 file.pages.inc file_add_form($form, &$form_state, $options = array())

Form callback for adding a file via an upload form.

This is a multi step form which has 1-4 pages:

  • Upload file
  • Choose filetype If there is only one candidate (based on mimetype) we will skip this step.
  • Edit scheme
  • Edit fields (Skip this step if there are no fields on this entity type.)

File

core/modules/file/file.pages.inc, line 17
Supports file operations including Manage and Delete.

Code

function file_add_form($form, &$form_state, $options = array()) {
  if (!is_array($options)) {
    $options = array($options);
  }
  $step = (isset($form_state['step']) && in_array($form_state['step'], array(1, 2, 3, 4))) ? $form_state['step'] : 1;

  $form['#step'] = $step;
  $form['#options'] = $options + array(
    'types' => array(),
    'enabledPlugins' => array(),
    'schemes' => array(),
    'max_filesize' => '',
    'uri_scheme' => 'public',
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['cancel'] = array(
    '#type' => 'link',
    '#title' => t('Cancel'),
    '#href' => 'admin/content/files',
    '#weight' => 15,
  );

  switch ($step) {
    case 1:
      $form['upload'] = array(
        '#type' => 'managed_file',
        '#title' => t('Upload a new file'),
        '#upload_location' => file_upload_destination_uri($options),
        '#upload_validators' => file_get_upload_validators($options),
        '#progress_indicator' => 'bar',
        '#pre_render' => array('file_managed_file_pre_render', 'file_upload_validators_pre_render'),
        '#default_value' => isset($form_state['storage']['upload']) ? $form_state['storage']['upload'] : NULL,
      );

      $form['actions']['next'] = array(
        '#type' => 'submit',
        '#value' => t('Next'),
      );

      form_load_include($form_state, 'inc', 'file', 'file.pages');

      return $form;

    case 2:
      return file_add_upload_step_filetype($form, $form_state, $options);

    case 3:
      return file_add_upload_step_scheme($form, $form_state, $options);

    case 4:
      return file_add_upload_step_fields($form, $form_state, $options);
  }
}