function form_example_tutorial_10

Example 10: A form with a file upload field.

This example allows the user to upload a file to Drupal which is stored physically and with a reference in the database.

See also

form_example_tutorial_10_submit()

form_example_tutorial_10_validate()

Related topics

1 string reference to 'form_example_tutorial_10'
form_example_menu in form_example/form_example.module
Implements hook_menu().

File

form_example/form_example_tutorial.inc, line 740

Code

function form_example_tutorial_10($form_state) {
    // If you are familiar with how browsers handle files, you know that
    // enctype="multipart/form-data" is required. Drupal takes care of that, so
    // you don't need to include it yourself.
    $form['file'] = array(
        '#type' => 'file',
        '#title' => t('Image'),
        '#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
    );
    return $form;
}