Example #1
0
 function create_attachments($attachments)
 {
     $attachments_objs = [];
     $timestamp = time();
     foreach ($attachments as $att) {
         $filename = $att[G2_FormMagic::FILE_NAME];
         $location = $att[G2_FormMagic::FILE_URI];
         if (file_exists($location)) {
             //Determine File name
             //				$filename = basename($file);
             $new_folder = $this->get_package_dir(true) . "mail_attachments/attached-{$timestamp}/{$filename}";
             //Create this new folder
             mkdir(dirname($new_folder), 0777, TRUE);
             //Move file to folder that will be attached
             rename($location, $new_folder);
             //Create the mail attachment db file
             $attachment = Mvc_Db::dispense(self::MAIL_ATTACHMENT);
             $attachment->filename = $filename;
             $attachment->uri = $new_folder;
             Mvc_Db::store($attachment);
             $attachments_objs[] = $attachment;
         }
     }
     return $attachments_objs;
 }