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

delete_alternative_file()

Description

delete_alternative_file

Parameters

ColumnTypeDefaultDescription
$resource int Resource id.
: $ref get_alternative_file$resource
$ref;
$ref int Alternative file id.

Location

include/resource_functions.php lines 5137 to 5202

Definition

 
function delete_alternative_file($resource$ref) : bool
    
{
    
# Delete any uploaded file.
    
$info=get_alternative_file($resource,$ref);
    if (!
$info)
        {
        return 
false;
        }

    
$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(),"schema");

        
// 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);
    
clear_query_cache("stats");

    return 
true;
    }

This article was last updated 12th December 2024 20:35 Europe/London time based on the source file dated 12th December 2024 10:55 Europe/London time.