Occidio
Occidio

Reputation: 165

Get selected file from media module

I am trying to get the file that the user has selected from the media selector from the media module in Drupal 7.

My form contains the selector and can upload and select a file successfully, but unable to get the name of the file that has been chosen.

My form for the selector:

$form['file'] = array(
    '#type' => 'media',
    '#title' => t('Screenshot'),
    '#description' => t('Upload an image of the feature (Optional)'),
),
);

I need to get the details of the selected file (e.g. name, directory)

Upvotes: 0

Views: 428

Answers (1)

Nicolas Pinos
Nicolas Pinos

Reputation: 137

Try to use hook_submit to check the file name.

Suposing the file field in your form is named "file":

function your_form_submit($form, &$form_state) {
  $file=$form_state['values']['file'];
  // do something...
  file_save($file);

You can use form_vaidate as well, i don't know exactly what you want to do with the file name...

Upvotes: 1

Related Questions