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

replace_resource_file()

Description

Replace the primary resource file with the file located at the path specified

Parameters

ColumnTypeDefaultDescription
$ref integer Resource ID to replace
$file_location
$no_exif false
$autorotate false
$keep_original true

Return

boolean

Location

include/resource_functions.php lines 6923 to 6976

Definition

 
function replace_resource_file($ref$file_location$no_exif false$autorotate false$keep_original true)
{
    global 
$replace_resource_preserve_option$notify_on_resource_change_days$lang$userref;
    
debug("replace_resource_file(ref=" $ref ", file_location=" $file_location ", no_exif=" . ($no_exif "TRUE" "FALSE") . " , keep_original=" . ($keep_original "TRUE" "FALSE"));

    
# FStemplate support - do not allow samples from the template to be replaced
    
if (resource_file_readonly($ref)) {
        return 
false;
    }

    
$resource get_resource_data($ref);
    if (
        !
get_edit_access($ref$resource["archive"], $resource)
        ||
        (
$resource["lock_user"] > && $resource["lock_user"] != $userref)
    ) {
        return 
false;
    }

    
// save original file as an alternative file
    
if ($replace_resource_preserve_option && $keep_original) {
        
// the following save may not succeed because there is no original in which case a debug log will have been created
        // allow replace resource to continue with its principal task of uploading
        
save_original_file_as_alternative($ref);
    }

    if (
filter_var($file_locationFILTER_VALIDATE_URL)) {
        
$uploadstatus upload_file_by_url($ref$no_exiffalse$autorotate$file_location);
        if (!
$uploadstatus) {
            
debug("replace_resource_file - upload_file_by_url() failed");
            return 
false;
        }
    } else {
        
$uploadstatus upload_file($ref$no_exiffalse$autorotate$file_locationfalsefalse);
        if (!
$uploadstatus) {
            
debug("replace_resource_file - upload_file() failed");
            return 
false;
        }
    }

    
hook('replace_resource_file_extra''', array($resource));
    
$log_ref resource_log($refLOG_CODE_REPLACED'''''');
    
daily_stat('Resource upload'$ref);
    
hook("additional_replace_existing""", array($ref,$log_ref));

    if (
$notify_on_resource_change_days != 0) {
        
// we don't need to wait for this.
        
ob_flush();
        
flush();
        
notify_resource_change($ref);
    }

    return 
true;
}

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.