You are here

function _mass_contact_process_attachments in Mass Contact 6

Same name and namespace in other branches
  1. 5.2 mass_contact.module \_mass_contact_process_attachments()

Check for attachments and process them, if one or more exists.

Parameters

message: The message, as it exists, so far.

boundary_id: The id to use as a boundary between attachments and the rest of the message.

Return value

The attachments, ready to be appended to the existing message.

1 call to _mass_contact_process_attachments()
mass_contact_mail_page_submit in ./mass_contact.module
Processes the main Mass Contact mail form.

File

./mass_contact.module, line 2206
This is the main code file for the Mass Contact module. This module enables users to contact multiple users through selected roles.

Code

function _mass_contact_process_attachments($message, $boundary_id) {
  $message .= "\n";

  // Loop through each possible attachment.
  for ($i = 1; $i <= variable_get('mass_contact_number_of_attachments', '3'); $i++) {

    // Check to see if the attachment exists.
    if ($_FILES['files']['size']['attachment_' . $i] > 0) {

      // Process the attachment.
      $message .= "--{$boundary_id}\n";
      $message .= "Content-Type: " . $_FILES['files']['type']['attachment_' . $i] . "; name=\"" . $_FILES['files']['name']['attachment_' . $i] . "\"\n";
      $message .= "Content-Transfer-Encoding: base64\n";
      $message .= "Content-Disposition: attachment; filename=\"" . $_FILES['files']['name']['attachment_' . $i] . "\"\n\n";
      if (file_exists($_FILES['files']['tmp_name']['attachment_' . $i])) {
        $message .= chunk_split(base64_encode(file_get_contents($_FILES['files']['tmp_name']['attachment_' . $i])));
      }
      else {
        $message .= chunk_split(base64_encode(file_get_contents(file_directory_temp() . '/' . $_FILES['files']['name']['attachment_' . $i])));
      }
      $message .= "\n";
    }
  }
  return $message;
}