Ad

Adding File Extension To Allowed List For File Uploads In OctoberCMS?

- 1 answer

The problem is in OctoberCMS backend within the File Manager of Assets, I receive the following error message when I attempt to upload a SVG file:

Error uploading file 'logo.svg': Only the following file types are allowed: jpg, jpeg, bmp, png, webp, gif, ico, css, js, woff, woff2, ttf, eot, json, md, less, sass, scss

The error message is generated from AssetList.php and references the function getDefinitions($type) in October\Rain\Filesystem.

    /**
     * Returns a definition set from config or from the default sets.
     * @param $type string
     * @return array
     */
    public function getDefinitions($type)
    {
        if (!method_exists($this, $type)) {
            throw new Exception(sprintf('No such definition set exists for "%s"', $type));
        }

        return (array) Config::get('cms.fileDefinitions.'.$type, $this->$type());
    }

I cannot find any references in /config/cms.php to 'fileDefinitions'.

How do I add SVG to the allowed file definitions array without losing the existing list of filetypes.

Ad

Answer

To upload a SVG that I have authored and know doesn't contain malicious code like embedded CSS and Javascript, I added the following to the bottom of the config: /config/cms.php.

    /*
    |--------------------------------------------------------------------------
    | File extensions list for allowed file uploads
    |--------------------------------------------------------------------------
    */

    'fileDefinitions' => [

        'assetExtensions' => [
            'svg', 'jpg', 'jpeg', 'bmp', 'png', 'webp', 'gif', 'ico', 'css', 'js', 'woff', 'woff2', 'ttf', 'eot', 'json', 'md', 'less', 'sass', 'scss'
        ],
    ],

Save, then the command to clear the cache and it solves the problem.

$ php artisan config:clear
Ad
source: stackoverflow.com
Ad