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

allow_in_browser()

Description

Check if file can be rendered in browser via download.php

Parameters

ColumnTypeDefaultDescription
$path string Path to file

Return

bool

Location

include/resource_functions.php lines 9244 to 9290

Definition

 
function allow_in_browser($path)
    {
    if(!
file_exists($path) || is_dir($path))
        {
        return 
false;
        }
    
// Permitted mime types can only be overridden by plugins
    
$permitted_mime[] = "application/pdf";
    
$permitted_mime[] = "image/jpeg";
    
$permitted_mime[] = "image/png";
    
$permitted_mime[] = "image/gif";
    
$permitted_mime[] = "image/webp";
    
$permitted_mime[] = "audio/mpeg";
    
$permitted_mime[] = "video/mp4";
    
$permitted_mime[] = "text/plain";
    
$permitted_mime[] = "text/csv";
    
$allow hook('allow_in_browser',"",[$permitted_mime]);
    if(
is_array($allow))
        {
        
$permitted_mime $allow;
        }

    if (
function_exists('mime_content_type'))
        {
        
$type mime_content_type($path);
        }
    else
        {
        
$type get_mime_type($path);
        }
    if(
$type == "application/octet-stream")
        {
        
# Not properly detected, try and get mime type via exiftool if possible
        
$exiftool_fullpath get_utility_path("exiftool");
        if (
$exiftool_fullpath!=false)
            {
            
$command=$exiftool_fullpath " -s -s -s -t -mimetype %PATH";
            
$cmd_args['%PATH'] = $path;
            
$type run_command($commandfalse$cmd_args);
            }
        }
    if(
in_array($type,$permitted_mime))
        {
        return 
true;
        }
    return 
false;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.