Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

get_resource_type_from_extension()

Description

Get resource type ID based on extension
$mappings = array(resource_type_id => array(allowed_extensions));

Example of mapping array:
$mappings = array(2 => array('pdf', 'doc', 'docx', 'epub', 'ppt', 'pptx', 'odt', 'ods', 'tpl'));

Parameters

ColumnTypeDefaultDescription
$extension string Extension we search by (ie. "mp4")
$resource_type_extension_mapping array Maps between resource types and extensions
$default integer The default value to use in case we can't find it the mappings

Return

integer Resource type ID

Location

include/resource_functions.php lines 7902 to 7916

Definition

 
function get_resource_type_from_extension($extension, array $resource_type_extension_mapping$default)
    {
    foreach(
$resource_type_extension_mapping as $resource_type_id => $allowed_extensions)
        {
        if (!
checkperm('T' $resource_type_id))
            {
            if(
in_array(strtolower($extension), $allowed_extensions))
                {
                return 
$resource_type_id;
                }
            }
        }

    return 
$default;
    }

This article was last updated 7th July 2020 11:05 Europe/London time based on the source file dated 6th July 2020 18:09 Europe/London time.