1

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.

Wittner
  • 583
  • 5
  • 21

3 Answers3

2

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.

Hardik Satasiya
  • 9,547
  • 3
  • 22
  • 40
  • That worked perfectly and I have accepted as the correct answer thank you. And I agree that the cms.php is the right way to do this. Thanks Hardik Satasiya and David Lundquist – Wittner Nov 27 '17 at 12:37
  • `This works` but how can i just add the extension (like adding item in array (array_push)) from the default extensions they provide. Is that possible ? – Mittul At TechnoBrave Mar 20 '18 at 05:44
  • i am not sure as its inside the config file so no direct way of editing it, any how we need to edit it manually, or rather making our own hook which can extend it but it will be more work – Hardik Satasiya Mar 20 '18 at 06:21
0

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]
                 ]

enter image description here

David Lundquist
  • 690
  • 7
  • 19
0

on CyberPanel I fixed it by following steps:

  1. Added made sure PHP version I am using is the same for what is for my website, i.e. 7.3
  2. Turned on file_uploads "ON" (Most important) (this is where everything started working good)
  3. Adding upload_tmp_dir dir might work but for me turning on only file_uploads worked
  4. Added /tmp directory to OpenLiteSpeed > Server Configuration > File Uploads
SFARPak
  • 49
  • 4