Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource 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 6835 to 6890

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

    
// save original file as an alternative file
    
if($replace_resource_preserve_option && $keep_original)
        {
        
$savedasalt save_original_file_as_alternative($ref); 
        if(!
$savedasalt
            {
            return 
false;
            }
        }

    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,true);
        if(!
$uploadstatus)
            {
            
debug("replace_resource_file - upload_file() failed");
            return 
false;
            }
        }

    
resource_log($ref,LOG_CODE_REPLACED,'','','');
    
daily_stat('Resource upload'$ref);
    
hook("additional_replace_existing");        
                        
    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 23rd November 2020 19:35 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.