I am working multi file upload functionality with different extensions(pdf,doc,png,jpg). Following code is working fine for multiple images upload. I would like to know how this code modify for different extension like doc, pdf, png,gif etc.
function mymodule_form($form, &$form_state) {
$form['file'] = array(
'#type' => 'file',
'#name' => 'files[]',
'#title' => t('Upload some photos'),
'#attributes' => array('multiple' => 'multiple'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
}
form mymodule_form_validate($form, &$form_state) {
//Save multiple files
$num_files = count($_FILES['files']['name']);
for ($i = 0; $i < $num_files; $i++) {
$file = file_save_upload($i, array(
'file_validate_is_image' => array(),
'file_validate_extensions' => array('png gif jpg jpeg'),
));
if ($file) {
if ($file = file_move($file, 'public://images')) {
$form_state['values']['file'][$i] = $file;
}
else {
form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
}
}
else {
form_set_error('file', t('No file was uploaded.'));
}
}
}