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 7581 to 7640

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_exif,false,$autorotate,$file_location);
        if(!
$uploadstatus)
            {
            
debug("replace_resource_file - upload_file_by_url() failed");
            return 
false;
            }
        }
    else
        {
        
$uploadstatus upload_file($ref,$no_exif,false,$autorotate,$file_location,false,false);
        if(!
$uploadstatus)
            {
            
debug("replace_resource_file - upload_file() failed");
            return 
false;
            }
        }

    
hook('replace_resource_file_extra''', array($resource));
    
$log_ref resource_log($ref,LOG_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 4th December 2024 08:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.