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

save_alternative_file()

Description

Updates the details of an alternative file in the database.

If a column is to be left as is then it must not be included in the array

Parameters

ColumnTypeDefaultDescription
$resource int The resource ID associated with the alternative file.
$ref int The reference ID of the alternative file to update.
$data array Array of data in name=>value format, where name is the resource_alt_files column name.
"description" > "s"
"alt_type" > "s"
"file_name" > "s"
"file_extension" > "s"
"file_size" > "i"
"unoconv" > "i"
];

Location

include/resource_functions.php lines 4721 to 4751

Definition

 
function save_alternative_file(int $resourceint $ref, array $data = []): void
{
    
$validcolumns = [
        
"name" => "s",
        
"description" => "s",
        
"alt_type" => "s",
        
"file_name" => "s",
        
"file_extension" => "s",
        
"file_size" => "i",
        
"unoconv" => "i",
    ];
    
$setcolumns = [];
    
$setparams = [];
    foreach (
$validcolumns as $column => $type) {
        if (isset(
$data[$column])) {
            
$setcolumns[] = $column;
            
$setparams[] = $type;
            
$setparams[] = $data[$column];
        }
    }
    if (
count($setcolumns) > 0) {
        
$setcolumnsql implode(" = ?, "$setcolumns) . " = ?";
        
$setparams array_merge($setparams, ["i"$resource"i"$ref]);
        
ps_query(
            
"UPDATE resource_alt_files
                     SET 
$setcolumnsql
                   WHERE resource = ? AND ref = ?"
,
            
$setparams
        
);
    }
}

This article was last updated 15th February 2025 20:35 Europe/London time based on the source file dated 14th February 2025 12:25 Europe/London time.