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

config_process_file_input()

Parameters

ColumnTypeDefaultDescription
$page_def array
$file_location
$redirect_location

Location

include/config_functions.php lines 1158 to 1253

Definition

 
function config_process_file_input(array $page_def$file_location$redirect_location)
    {
    global 
$baseurl$storagedir$storageurl$banned_extensions;

    
$file_server_location $storagedir '/' $file_location;

    
// Make sure there is a target location
    
if(!(file_exists($file_server_location) && is_dir($file_server_location)))
        {
        
mkdir($file_server_location0777true);
        }

    
$redirect false;

    foreach(
$page_def as $page_element)
        {
        if(
$page_element[0] !== 'file_input')
            {
            continue;
            }

        
$config_name $page_element[1];
        
$valid_extensions $page_element[5];

        
// DELETE
        
if (
            
getval('delete_' $config_name'') !== '' 
            
&& enforcePostRequest(false)
            && 
get_config_option(null$config_name$delete_filename)
            ) {
                
$delete_filename str_replace('[storage_url]' '/' $file_location$file_server_location$delete_filename);

                if(
file_exists($delete_filename))
                    {
                    
unlink($delete_filename);
                    
hook("configdeletefilesuccess",'',array($delete_filename));
                    }
                
delete_config_option(null$config_name);
                
$redirect true;
            }
        
// CLEAR
        
if (
            
getval('clear_' $config_name'') !== '' 
            
&& enforcePostRequest(false)
            && 
get_config_option(null$config_name$missing_file)
            ) {
                
$missing_file str_replace('[storage_url]' '/' $file_location$file_server_location$missing_file);
                 if(!
file_exists($missing_file))
                    {
                    
set_config_option(null$config_name'');

                    
$redirect true;
                    }
            }

        
// UPLOAD
        
if(getval('upload_' $config_name'') !== '' && enforcePostRequest(false))
            {
            if(isset(
$_FILES[$config_name]['tmp_name']) && is_uploaded_file($_FILES[$config_name]['tmp_name']))
                {
                
$uploaded_file_pathinfo  pathinfo($_FILES[$config_name]['name']);
                
$uploaded_file_extension $uploaded_file_pathinfo['extension'];
                
$uploaded_filename       sprintf('%s/%s.%s'$file_server_location$config_name$uploaded_file_extension);
                
// We add a placeholder for storage_url so we can reach the file easily 
                // without storing the full path in the database
                
$saved_filename          sprintf('[storage_url]/%s/%s.%s'$file_location$config_name$uploaded_file_extension);

                if(
is_banned_extension($uploaded_file_extension))
                    {
                    
trigger_error('You are not allowed to upload "' $uploaded_file_extension '" files to the system!');
                    }
                
                if (
count($valid_extensions) > && !check_valid_file_extension($_FILES[$config_name], $valid_extensions))
                    {
                    
trigger_error('File type not valid for this selection. Please choose from ' implode(', '$valid_extensions) . '.');
                    }

                if(!
move_uploaded_file($_FILES[$config_name]['tmp_name'], $uploaded_filename))
                    {
                    unset(
$uploaded_filename);
                    }
                }

            if(isset(
$uploaded_filename) && set_config_option(null$config_name$saved_filename))
                {
                
$redirect true;
                
hook("configuploadfilesuccess",'',array($uploaded_filename));
                }
            }
        }

    if(
$redirect)
        {
        
redirect($redirect_location);
        }
    }

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