I am using Drupal 7 and have a custom module that creates a form that has a file upload field:
$form['resume_file'] = array(
'#type' => 'file',
'#title' => t('Resume Upload'),
);
I need to make sure the file extensions are one of the following: doc, docx, pdf, txt and rtf and that the file size is no larger than 2MB
I am not finding a clear way in the docs to accomplish this. I saw one place that said use this:
$form['resume_file'] = array(
'#type' => 'file',
'#title' => t('Resume Upload'),
'#upload_validators' => array("file_validate_extensions" => array("doc docx pdf txt rtf")),
);
but that didn't do anything as far as blocking the wrong filetype and giving an error message. Do I need to do something else like have something extra in my hook_form_validate() function?
I also saw this:
$form['resume_file'] = array(
'#type' => 'file',
'#title' => t('Resume Upload'),
);
$form['resume_file']['#upload_validators']['file_validate_extensions'][0] = 'doc docx pdf txt rtf';
Which also did not do anything. How do I validate for file size and extensions?