Collections functions
General functions
Render functions
Theme permission functions
Resource functions

delete_alternative_file()

Parameters

ColumnTypeDefaultDescription
$resource
$ref

Location

include/resource_functions.php lines 4579 to 4638

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);
    
hook('delete_alternative_file_extra''', array($path));
    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 ps_array('select id value from preview_size',array());

        
// 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);
        }

        
hook('delete alternative_jpg_extra''', array($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);
                    
hook('delete_alternative_file_loop''', array($path));
                    if (
file_exists($path)) {
                        
unlink($path);
                        
$page++;
                    }
                }
            }
        }
        
hook('delete_alternative_mp3_extra''', array($path));

    
# Delete the database row
    
ps_query("delete from resource_alt_files where resource=? and ref=?", array("i",$resource,"i",$ref));

    
# Log the deletion
    
resource_log($resource,LOG_CODE_DELETED_ALTERNATIVE,'');

    
# Update disk usage
    
update_disk_usage($resource);

    return 
true;
    }

This article was last updated 4th October 2022 10:35 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.