Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Hack for Expression Engine for file attachments

// description of your code here

Hm- not out of the box.  There may be a plugin/extension floating around for it.  I’ve hacked it- was pretty easy.  The core email class already has the code you need for attaching files.  So you pretty much just have to modify the mod.email.php file- around 207 I changed the content type:
$data['enctype']                 = 'multipart/form-data';

Around 530 I added an array of uploaded files:
// hack for uploads
        $att = array();
        

        if (isset($_FILES) AND (count($_FILES) > 0))
        {
            $att_ret = $this->upload_file();
            foreach ($att_ret as $key=> $val)
            {
            $att[] = '/home/whatever/mail_attach/'.$val['name'];
            }
        }

Around 865 you need to tie the attached files to the email:
// hack for attachments
        if (count($att) > 0)
        {
        foreach($att as $val)
        {
                $email->attach($val);
        }
        }

After the emails are sent, I deleted the files:
// hack- delete the attached files from server
        
        if (isset($att) AND count($att) > 0)
        {
            foreach ($att as $val)
            {
                @unlink($val);
            }
        }

Then you need to add a function to handle the actual uploading- it’s easy because you can use the upload class- I think I modeled it after the file upload module because I needed to be able to upload multiple files.  Anyway- this part is a bit dangerous as you’re letting any idiot upload stuff.  So watch that you keep things as secure as possible- be sure everything is gettingscrubbed down’ and such. 

You need to create an account or log in to post comments to this site.