October CMS disallowed file types

强颜欢笑 提交于 2019-12-24 07:05:14

问题


I'm trying to upload a .pptx file to the media library in October CMS and I'm getting an error because the filetype is not allowed. I have tried using the following suggestion from Stackoverflow:

'fileDefinitions' => [ 'assetExtensions' => array_merge(FileDefinitions::get('assetExtensions'), ['docx']), ],

But I get an error message about FileDefinitions class not existing. I have also tried another suggestion of adding to a fileTypes array in /config/cms.php but that doesn't work either as this way of including files seems to be gone.

The October CMS git repo had a pull request which added a file type to the source code but I feel this is not a great idea as different users have different needs and the system would have to be updated every time someone wants a new file type added! Anyway, does anyone know a good way that works of simply adding a new file type the the allow file types array?

Seems like it should be a simple config setting but for the life of me I can't find any working reference.


回答1:


I guess you added wrong extension there its pptx not ppxt @David Lundquist

<?php

return [

    'fileDefinitions' => [
        'defaultExtensions' => [
            'pptx'
         ]
    ],

    // other config
    ....
];

just add this lines to the config/cms.php config and it should work.

but now make sure that it will now only allow files .pptx if you want to allow more extensions you need to add them here manually.

'jpg', 'jpeg', 'bmp', 'png', 'webp', 'gif', 'svg', 'js', 'map', 'ico', 'css', 'less', 'scss', 'ics', 'odt', 'doc', 'docx', 'pdf', 'swf', 'txt', 'xml', 'ods', 'xls', 'xlsx', 'eot', 'woff', 'woff2', 'ttf', 'flv', 'wmv', 'mp3', 'ogg', 'wav', 'avi', 'mov', 'mp4', 'mpeg', 'webm', 'mkv', 'rar', 'zip'

this is the default list so just copy this list and add your own extra extension here..

in you case its pptx .. and it will work.

I have checked code base there is no other easy way to extend this. { probably hard way require extra plugins and hooks etc ..}

Do not try that array_merge solution as FileDefinitions code will recursively called to get cms config again it will do array_merge ... (out of the topic but it will not work so do not try that)

so better to use this one and this will not affect on updates.

updated every time someone wants a new file type added!

don't worry for only this purpose they provided config files :)

try it, if its not working please comment.




回答2:


if you want to upload a particular file extension to the media library you will need to go to the cms config

cms.php and add

        'fileDefinitions' => [
                'defaultExtensions' => [
                    'ppxt',...10billion more extensions in a list here]
                 ]



来源:https://stackoverflow.com/questions/47416253/october-cms-disallowed-file-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!