Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

config_process_file_input()

Parameters

ColumnTypeDefaultDescription
$page_def array
$file_location
$redirect_location

Location

include/config_functions.php lines 951 to 1040

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];

        
// DELETE
        
if(getval('delete_' $config_name'') !== '' && enforcePostRequest(false))
            {
            if(
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));
                    }
                
set_config_option(null$config_name'');
                
$redirect true;
                }
            }
        
// CLEAR
        
if(getval('clear_' $config_name'') !== '' && enforcePostRequest(false))
            {
            if(
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(
in_array($uploaded_file_extension$banned_extensions))
                    {
                    
trigger_error('You are not allowed to upload "' $uploaded_file_extension '" files to the system!');
                    }

                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 12th July 2020 04:35 Europe/London time based on the source file dated 8th July 2020 11:40 Europe/London time.