Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

delete_alternative_file()

Parameters

ColumnTypeDefaultDescription
$resource
$ref

Location

include/resource_functions.php lines 3943 to 3995

Definition

 
function delete_alternative_file($resource,$ref)
    {
    
# Delete any uploaded file.
    
$info=get_alternative_file($resource,$ref);
    
$path=get_resource_path($resourcetrue""true$info["file_extension"], -11false""$ref);
    if (
file_exists($path)) {unlink($path);}
    
        
// run through all possible extensions/sizes
    
$extensions = array();
    
$extensions[]=$info['file_extension']?$info['file_extension']:"jpg";
    
$extensions[]=isset($info['preview_extension'])?$info['preview_extension']:"jpg";
    
$extensions[]=$GLOBALS['ffmpeg_preview_extension'];
        
$extensions[]='jpg'// always look for jpegs, just in case
    
$extensions[]='icc'// always look for extracted icc profiles
    
$extensions=array_unique($extensions);
        
$sizes sql_array('select id value from preview_size');
    
        
// in some cases, a jpeg original is generated for non-jpeg files like PDFs. Delete if it exists.
        
$path=get_resource_path($resourcetrue,''true'jpg', -11false""$ref);
        if (
file_exists($path)) {
            
unlink($path);
        }

        
// in some cases, a mp3 original is generated for non-mp3 files like WAVs. Delete if it exists.
        
$path=get_resource_path($resourcetrue,''true'mp3', -11false""$ref);
        if (
file_exists($path)) {
            
unlink($path);
        }

        foreach (
$extensions as $extension){
            foreach (
$sizes as $size){
                
$page 1;
                
$lastpage 0;
                while (
$page <> $lastpage){
                    
$lastpage $page;
                    
$path=get_resource_path($resourcetrue$sizetrue$extension, -1$pagefalse""$ref);
                    if (
file_exists($path)) {
                        
unlink($path);
                        
$page++;
                    }
                }
            }
        }
        
    
# Delete the database row
    
sql_query("delete from resource_alt_files where resource='" escape_check($resource) . "' and ref='" escape_check($ref) . "'");
    
    
# Log the deletion
    
resource_log($resource,LOG_CODE_DELETED_ALTERNATIVE,'');
    
    
# Update disk usage
    
update_disk_usage($resource);
    }

This article was last updated 16th July 2020 00:35 Europe/London time based on the source file dated 15th July 2020 16:26 Europe/London time.