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 6929 to 6982

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 18th March 2025 14:35 Europe/London time based on the source file dated 6th March 2025 14:30 Europe/London time.