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 8631 to 8654

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 8th December 2024 20:35 Europe/London time based on the source file dated 6th December 2024 14:05 Europe/London time.