function _contact_attach_upload_validate in Contact Attach 6
Same name and namespace in other branches
- 5 contact_attach.module \_contact_attach_upload_validate()
Validate the attachment(s).
2 calls to _contact_attach_upload_validate()
- contact_attach_contact_mail_page_validate in ./
contact_attach.module - Add custom validation to verify the attachments.
- contact_attach_contact_mail_user_validate in ./
contact_attach.module - Add custom validation to verify the attachments.
File
- ./
contact_attach.module, line 524 - Allows attaching files to e-mails sent using the site-wide contact form.
Code
function _contact_attach_upload_validate() {
global $user;
// Validate file against all users roles.
// Only denies an upload when all roles prevent it.
foreach ($user->roles as $rid => $name) {
// Validate the file type, based on file extension.
$extensions = variable_get("upload_extensions_{$rid}", variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'));
// Validate the upload limit, based on file size.
$file_limit = variable_get("upload_uploadsize_{$rid}", variable_get('upload_uploadsize_default', 1)) * 1024 * 1024;
// Validate the upload limit, based on the user's uploads.
$user_limit = variable_get("upload_usersize_{$rid}", variable_get('upload_usersize_default', 1)) * 1024 * 1024;
$validators = array(
'file_validate_extensions' => array(
$extensions,
),
'file_validate_name_length' => array(),
'file_validate_size' => array(
$file_limit,
$user_limit,
),
);
// Loop through each possible attachment.
for ($i = 1; $i <= variable_get('contact_attach_number', '3'); $i++) {
file_save_upload('contact_attach_' . $i, $validators);
}
}
}