Attachment issues

VVT

Active Member
Hi peeps,

Seeing some forum posts regarding issues in sending attachments via APIs. Just wanted to give you ppl a simple and easy workaround on the same. You can actually upload the attachments to ckeditor filemanager and then put a direct download link on the email. You would upload the files just like the images. But, remember that only image types are currently allowed by default.

You can edit apps/common/extensions/ckeditor/controllers/Ext_ckeditorController.php and update the " uploadAllow" value to something like this to allow additional extensions ->
PHP:
$uploadAllow = array('image','application/pdf','application/msword','application/vnd.ms-word','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.presentation','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/x-bzip','application/x-compressed-tar','application/x-gzip','application/x-rar','application/x-tar','application/zip','text/plain','text/calendar','text/directory');

Now, you should be able to upload files with the specified extensions.

Advantages :

1. You can enhance the speed of delivery since less data is transferred.
2. Reduce bandwidth.
3. Less computing power required.
4. Emails will be lighter and reduce the "spamminess" of your emails.
5. Cost reduction if using 3rd party ESPs.
6. You can track the downloads.

Think, a 5MB attachment sent to 10K subscribers will result in 50GB of storage space at the recipient ISP - something that no ISP will be happy about.

Also, the changes you make to the above file will be overridden on the next MW update.

@twisted1919 Can you allow a custom file to specify additional extensions so that changes will persist even after MW update ?
 
The above method will not need you to attach any file to the email, rather, you would be able to upload those to CKEditor filemanager and then put a direct download link on your email for the recipients to download it. So, it will be just another regular email but containing a download link to your attachments. So, you should be able to relay them to 3rd party ESPs like you do for usual emails without attachments.

Attachment part would be similar to this : http://kb.mailchimp.com/campaigns/images-videos-files/share-files-with-subscribers
 
The way we handle attachments is to have a folder with the attachments inside and then have a simple link to it in the email. No problem with mwz as no attachment is sent or uploaded via mwz.
 
@VVT - we have a hook there that you can use:
PHP:
Yii::app()->hooks->addFilter('ext_ckeditor_el_finder_options', function($options){
    $options['roots'][0]['uploadAllow'] = array('image','application/pdf','application/msword','application/vnd.ms-word','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.presentation','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/x-bzip','application/x-compressed-tar','application/x-gzip','application/x-rar','application/x-tar','application/zip','text/plain','text/calendar','text/directory');

    return $options;
});
 
@ Corey : apps/common/extensions/ckeditor/controllers/Ext_ckeditorController.php
Thanks @Vpul Shah

You can connect to hooks from your theme's run() method or from your extension run() method.
@twisted1919, so would it be as simple as creating an extension, then under "// run the extension, this is mandatory" add:
PHP:
Yii::app()->hooks->addFilter('ext_ckeditor_el_finder_options', function($options){
    $options['roots'][0]['uploadAllow'] = array('image','application/pdf','application/msword','application/vnd.ms-word','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.presentation','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/x-bzip','application/x-compressed-tar','application/x-gzip','application/x-rar','application/x-tar','application/zip','text/plain','text/calendar','text/directory');

    return $options;
});
 
@corey34 - this is correct.
That's what I did and when I upload the extension, it tells me that it was uploaded successfully, but then it does not show up in my list of uploaded extensions.

Here is exactly what the extension looks like:
PHP:
<?php defined('MW_PATH') || exit('No direct script access allowed');

class ckeditorallowfiletypes extends ExtensionInit
{
    // name of the extension as shown in the backend panel
    public $name = 'ckeditor extension - more files';
 
    // description of the extension as shown in backend panel
    public $description = 'Allows more file types to uploaded through ckeditor';
 
    // current version of this extension
    public $version = '1.0';

    // the author name
    public $author = 'none';
 
    // author website
    public $website = 'none';
 
    // contact email address
    public $email = 'none';
 
    // in which apps this extension is allowed to run
    public $allowedApps = array('customer');

    // can this extension be deleted? this only applies to core extensions.
    protected $_canBeDeleted = true;
 
    // can this extension be disabled? this only applies to core extensions.
    protected $_canBeDisabled = true;

    // run the extension, ths is mandatory
    Yii::app()->hooks->addFilter('ext_ckeditor_el_finder_options', function($options){
        $options['roots'][0]['uploadAllow'] = array('image','application/pdf','application/msword','application/vnd.ms-word','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.presentation','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/x-bzip','application/x-compressed-tar','application/x-gzip','application/x-rar','application/x-tar','application/zip','text/plain','text/calendar','text/directory');

        return $options;
    });

}
 
class ckeditorallowfiletypes extends ExtensionInit
Nope.

This is how you do it:
PHP:
<?php defined('MW_PATH') || exit('No direct script access allowed');

class CkeditorallowfiletypesExt extends ExtensionInit
{
    // name of the extension as shown in the backend panel
    public $name = 'ckeditor extension - more files';

    // description of the extension as shown in backend panel
    public $description = 'Allows more file types to uploaded through ckeditor';

    // current version of this extension
    public $version = '1.0';

    // the author name
    public $author = 'none';

    // author website
    public $website = 'none';

    // contact email address
    public $email = 'none';

    // in which apps this extension is allowed to run
    public $allowedApps = array('customer');

    // can this extension be deleted? this only applies to core extensions.
    protected $_canBeDeleted = true;

    // can this extension be disabled? this only applies to core extensions.
    protected $_canBeDisabled = true;

    // run the extension, ths is mandatory
    public function run()
    {
        Yii::app()->hooks->addFilter('ext_ckeditor_el_finder_options', function($options){
            $options['roots'][0]['uploadAllow'] = array('image','application/pdf','application/msword','application/vnd.ms-word','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.presentation','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/x-bzip','application/x-compressed-tar','application/x-gzip','application/x-rar','application/x-tar','application/zip','text/plain','text/calendar','text/directory');

            return $options;
        });
    }

}
 
If I wanted to allow some other types of files, do I follow the pattern of adding "application/[FILE TYPE]"?

For example, if I wanted to allow customers to add .epub files, would I just add "application/epub"? I have tried that and it doesn't work.

Thanks
 
Back
Top