Collections functions
General functions
Render functions
Theme permission functions
Resource 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 8712 to 8757

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[] = "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 26th September 2022 21:05 Europe/London time based on the source file dated 26th September 2022 17:00 Europe/London time.