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

safe_file_name()

Description

Ensures the filename cannot leave the directory set.

Parameters

ColumnTypeDefaultDescription
$name string

Return

string

Location

include/file_functions.php lines 9 to 28

Definition

 
function safe_file_name($name)
{
    
// Returns a file name stripped of all non alphanumeric values
    // Spaces are replaced with underscores
    
$alphanum 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
    
$name str_replace(' ''_'$name);
    
$newname '';

    for (
$n 0$n strlen($name); $n++) {
        
$c substr($name$n1);
        if (
strpos($alphanum$c) !== false) {
            
$newname .= $c;
        }
    }

    
// Set to 250 to allow for total length to be below 255 limit including filename and extension
    
$newname mb_substr($newname0250);

    return 
$newname;
}

This article was last updated 11th February 2025 19:05 Europe/London time based on the source file dated 21st January 2025 15:20 Europe/London time.