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
bool { $path:
$path string Path to file

Location

include/resource_functions.php lines 8511 to 8543

Definition

 
function allow_in_browser($path): bool
{
    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 array_values(array_filter([mime_content_type($path)]));
    } else {
        
$type get_mime_type($path);
    }

    
// Unsure? Try and get mime type via exiftool if possible
    
if ($type === ['application/octet-stream']) {
        
$type get_mime_type($pathnulltrue);
    }

    return 
array_intersect($permitted_mime$type) !== [];
}

This article was last updated 29th May 2025 21:35 Europe/London time based on the source file dated 28th May 2025 12:00 Europe/London time.