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_file_input()

Description

Generate an HTML input file with its own form

Parameters

ColumnTypeDefaultDescription
$name string HTML input file name attribute
$label string
$current
$form_action string URL where the form should post to
$width int 420 Wdidth of the input file HTML tag. Default - 420
$valid_extensions array
$file_preview false

Location

include/config_functions.php lines 557 to 663

Definition

 
function config_file_input($name$label$current$form_action$width 420$valid_extensions = array(), $file_preview false)
    {
    global 
$lang,$storagedir;

    if(
$current !=='')
        {
        
$origin_in_config = (substr($current013) != '[storage_url]') && mb_strpos($current'system/config') === false;
        if (
$origin_in_config)
            {
            
# Current value may have originated in config.php - file uploader to consider this unset
            # to enable override of config.php by uploading a file.
            
$current '';
            }
        else
            {
            
$missing_file str_replace('[storage_url]'$storagedir$current);
            
$pathparts=explode("/",$current);
            }
        }

    
?>
    <div class="Question" id="question_ echo escape($name); ?>">
        <form method="POST" action=" echo escape($form_action); ?>" enctype="multipart/form-data">
        <label  if ($file_preview && $current !== "") {echo 'id="config-image-preview-label"';} ?> for=" echo escape($name); ?>"> echo escape($label); ?></label>
        <div class="AutoSaveStatus">
        <span id="AutoSaveStatus- echo escape($name); ?>" style="display:none;"></span>
        </div>
        
        
if($current !== '' && $pathparts[1]=="system" && !file_exists($missing_file))
            {
            
?>
            <span> echo escape($lang['applogo_does_not_exists']); ?></span>
            <input type="submit" name="clear_ echo escape($name); ?>" value=" echo escape($lang["clearbutton"]); ?>">
            
            
}
        elseif(
'' === $current || !get_config_option(null$name$current_option) || $current_option === '')
            {
            
?>
            <input type="file" name=" echo escape($name); ?>" style="width: echo (int) $width?>px">
            <input type="submit" name="upload_ echo escape($name); ?> if (count($valid_extensions) > 0) {echo 'onclick="return checkValidExtension_' escape($name) . '()"';} ?> value=" echo escape($lang['upload']); ?>">
            
            
if (count($valid_extensions) > 0)
                {
                
?>
                <script>
                function checkValidExtension_ echo escape($name?>()
                    {
                    let file_path = document.getElementsByName(" echo escape($name); ?>")[0].value;
                    let ext = file_path.toLowerCase().substr(file_path.lastIndexOf(".")+1);
                    let valid_extensions = [
                        
foreach ($valid_extensions as $extension) {
                            echo 
'"' escape($extension) . '",';
                        } 
?>];
                    if (file_path != "" && valid_extensions.includes(ext)) return true;
                    alert( echo '"' escape(str_replace('[extensions]'implode(', '$valid_extensions), $lang['systemconfig_invalid_extension'])) .'"'?>);
                    return false;
                    }
                </script>
                
                
}
            }
        else
            {
            
$file_location str_replace('[storage_url]'$storagedir$current);
            if (
function_exists('mime_content_type'))
                {
                
$mime_type explode("/"mime_content_type($file_location));
                }
            else
                {
                
$mime_type explode("/"get_mime_type($file_location));
                }
            
$file_type end($mime_type);
            
$file_size str_replace("&nbsp;"," ",formatfilesize(filesize($file_location)));
            
?>
            <span style="width: 316px;display: inline-block;"> echo escape("$file_type ($file_size)"); ?></span>
            <input type="submit" name="delete_ echo escape($name); ?>" value=" echo escape($lang['action-delete']); ?>">
            
            
}
            
generateFormToken($name);
            
?>
        </form>
        
        
if ($file_preview && $current !== "") {
            global 
$baseurl

            
$matches = array();

            if (
preg_match("/system\/config.*/"$current$matches) && count($matches) == 1) {
                
$img_url $baseurl '/filestore/' $matches[0];
            } else {
                
$img_url $baseurl '/filestore/' str_replace('[storage_url]/'''$current);
            }

            
?>
            <div id="preview_ echo escape($name); ?>">
                <img class="config-image-preview"
                    src=" echo escape($img_url) . '?v=' date("s"?>"
                    alt=" echo escape($lang["preview"] . ' - ' $label?>">
            </div>
            
        
}
        
?>
        <div class="clearerleft"></div>
    </div>
    
    
}

This article was last updated 15th December 2024 10:05 Europe/London time based on the source file dated 11th December 2024 15:55 Europe/London time.