How can I validate, via Webform module (using Webform file upload in Drupal 7) whether the file has been uploaded or not?

How can I handle and reference those files?

Seems that normal FAPI calls don't work (e. g. file_save_upload('file1') returns a non-true value if I have a file field).

I see that Webform file fields upload the file BEFORE form submission (i. e. clicking "upload to server" adjacent button).

I don't know if that's the normal file-upload behavior or it's a specific behavior.

How can I handle the files in that way? I need to validate if at least one of those fields was uploaded (assume they are named foto1, foto2, foto3, foto4), and later I need to reference those files (e.g. getting a public link to them).

1 Answer 1


Found it -.-''.

$form_state['values']['submitted']['foto1'] returns integer 0, which is a "no file" id, instead of another value (webform for Drupal 7 currently returns a numeric string as id). File extension validation and other rules have been executed beforehand, and finally the obtained id can be loaded with webform_get_file($form_state['values']['submitted']['foto1']), obtaining a managed_file entity (actually, as a stdClass instance).

This is the result of DPM-ing the four fields using dev tools in Drupal 7, where foto4 is not filled. The four entries correspond to calls to webform_get_file($form_state['values']['submitted']['foto1']) to foto4-corresponding field path.

Debug sample output from dpm when inspecting

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.