Allow other types of files to be added to the default add file admin page for media

The media module allows changing allowed file types that can be loaded when using fields but not at /file/add. So, here's how I got around that:

/**
 * Implements hook_menu_alter().
 * 
 * Alters the allowed filetypes to be uploaded via the page located at /file/add.
 *
 * In this case, allows the regular ones plus .ics files.
 */
function mymodule_menu_alter(&$items) {
  if (isset($items['file/add']['page arguments'][1])) {
    $items['file/add']['page arguments'][1]['file_extensions'] = 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp ics';
  }
}

Tags

Article Type

General