Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 540 to 626

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]');
        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);
            
$mime_type explode("/",mime_content_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?>
            <div id="preview_ echo escape($name); ?>">
            <img class="config-image-preview" src=" echo escape($baseurl '/filestore/' str_replace('[storage_url]/'''$current)) . '?v=' date("s"?>" alt=" echo escape($lang["preview"] . ' - ' $label?>">
            </div>
             ?>
        <div class="clearerleft"></div>
    </div>
    
    
}

This article was last updated 19th March 2024 11:35 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.