Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 8652 to 8675

Definition

 
function get_resource_type_from_extension($extension, array $resource_type_extension_mapping$default)
    {
    
$resource_types ps_array("SELECT ref AS value FROM resource_type",array());
    foreach(
$resource_type_extension_mapping as $resource_type_id => $allowed_extensions)
        {
        if (
            !
checkperm('T' $resource_type_id)
            && 
in_array(strtolower($extension), $allowed_extensions)
            && 
in_array($resource_type_id$resource_types)
            ) {
                return 
$resource_type_id;
            }
        }
    if(
in_array($default$resource_types))
        {
        return 
$default;
        }
    else
        {
        
// default resource type does not exist so use the first available type
        
sort($resource_types,SORT_NUMERIC);
        return 
$resource_types[0];
        }
    }

This article was last updated 14th December 2024 08:35 Europe/London time based on the source file dated 13th December 2024 14:45 Europe/London time.