0

I have this managed_file form in a Drupal customized module, with this form a user can upload an image and saved it under sites/defaults/files.

 $form['Background_image'] = array(
'#type' => 'managed_file',
'#title' => t('Image'),
'#progress_message' => t('Please wait...'),
 '#progress_indicator' => 'bar',
'#description' => t('Click "Browse..." to select an image to upload.'),
'#required' => TRUE,
 ///'#upload_validators' => array('file_validate_extensions' => array('jpeg jpg png gif')),
'#upload_location' => 'public://backgroundimage/'
'#default_value' => $this->options['Background image'],
);

how to add a function to get the uploaded file? I tried this but it didnt work.

$image = file_load($form_state['values']['Background_image']);
5
  • Where are you saving the file ID after the form submits? Is this a system_settings_form()?
    – Clive
    Oct 4, 2013 at 14:47
  • yes a system_settings_form() Oct 4, 2013 at 14:50
  • What do you get for variable_get('Background_image')? Does it contain the expected file ID?
    – Clive
    Oct 4, 2013 at 14:52
  • normaly it returns the downloaded file..but Im not sure Oct 4, 2013 at 14:56
  • No it'll never return a downloaded file, only the file ID. Just run that code and see what's in it. If you get the file ID, use it with file_load() and you'll get the file object back. If not, just update your question because I think the scope will have shifted a bit
    – Clive
    Oct 4, 2013 at 15:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.