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

handle_rsc_upload()

Description

Handle the POST for an upload of a plugin configuration (.rsc) file

Typically invoked near the beginning of a plugin's setup.php file
something like this:

if (getval('upload','')!='')
{
handle_rsc_upload($plugin_name);
)
elseif (getval('submit','')!='')
{
...
}

Parameters

ColumnTypeDefaultDescription
$plugin_name string - the name of the plugin

Return

string a translated string giving the status of the upload

Location

include/plugin_functions.php lines 414 to 452

Definition

 
function handle_rsc_upload($plugin_name)
    {
    global
$lang;
    
$upload_status=$lang['plugins-goodrsc'];
    if (!
function_exists('json_decode'))
        {
        
$upload_status str_replace('%version','5.2',$lang['error-oldphp']);
        }
    elseif ((
$_FILES['rsc_file']['error'] != 0) || (pathinfo($_FILES['rsc_file']['name'], PATHINFO_EXTENSION)!='rsc') ||
            !
is_uploaded_file($_FILES['rsc_file']['tmp_name']) || ($_FILES['rsc_file']['size'] > 32768))
        {
        
$upload_status $lang['plugins-didnotwork'];
        }
    else
        {
        
$json file_get_contents($_FILES['rsc_file']['tmp_name']);
        if (
substr($json03) == (chr(0xEF) . chr(0xBB) . chr(0xBF))) // Discard UTF-8 BOM if present
            
{
            
$json substr($json3);
            }
        
$tok "\n";
        
$rsc_plugin_name json_decode(strtok($json$tok),true);
        if (
$rsc_plugin_name['ResourceSpacePlugin'] == $plugin_name)
            {
            
$config json_decode(strtok($tok), true);
            foreach(
$config as $key=>$value)
                
$GLOBALS[$key] = $value;
            }
        elseif (
$rsc_plugin_name == '')
            {
            
$upload_status $lang['plugins-badrsc'];
            }
        else
            {
            
$upload_status str_replace('%plugin',$rsc_plugin_name['ResourceSpacePlugin'],$lang['plugins-wrongplugin']);
            }
        }
    return 
$upload_status;
    }

This article was last updated 27th September 2021 11:35 Europe/London time based on the source file dated 3rd September 2021 13:30 Europe/London time.