Problem
I have a custom form with three file fields. The files are selected, then on submit they're attached to an email and sent off with a call to hook_mail
.
I'm pretty sure the files aren't saved to the server and I don't want them saved as the files might be sensitive information.
But I want the fields to support certain file extensions. How can I validate them?
So Far
There is a function: file_validate_extensions
which can validate but it only works for Drupal file objects and since these are never uploaded I'm not sure that works.
I tried using file_save_upload
, as when a file is selected in a form (and not immediately uploaded) it's information appears in $_FILES so I tried to load the temporary path given there however it doesn't work.
(The path is of the form: C:\XAMPP\tmp\phpEDC6.tmp
)
function mymodule_form_submit($form, $form_state) {
$coverincluded = file_save_upload($_FILES['files']['tmp_name']['cover_letter_included'],
array(
'file_validate_is_image' => array(), // Validates file is really an image.
'file_validate_extensions' => array('png gif jpg jpeg'), // Validate extensions.
));
//unfortunately this dpm never shows, presumably because file_save_upload hasn't worked
dpm($coverincluded);
}