Collections functions
General functions
Render functions
Theme permission functions
Resource functions

update_disk_usage()

Parameters

ColumnTypeDefaultDescription
$resource

Location

include/resource_functions.php lines 5583 to 5609

Definition

 
function update_disk_usage($resource)
    {
    
# we're also going to record the size of the primary resource here before we do the entire folder
    
$ext ps_value("SELECT file_extension value FROM resource where ref = ? AND file_path IS NULL",array("i",$resource), 'jpg');
    
$path get_resource_path($resource,true,'',false,$ext);
    if (
file_exists($path)){
        
$rsize filesize_unlimited($path);
    } else {
        
$rsize 0;
    }

    
# Scan the appropriate filestore folder and update the disk usage fields on the resource table. Use the thm size so that we don't get a Staticsync location
    
$dir=dirname(get_resource_path($resource,true,"thm",false));
    if (!
file_exists($dir)) {return false;} # Folder does not yet exist.
    
$d dir($dir);
    
$total=0;
    while (
$f $d->read())
        {
        if (
$f!=".." && $f!=".")
            {
            
$s=filesize_unlimited($dir "/" .$f);
            
$total+=$s;
            }
        }
    
ps_query("update resource set disk_usage=?,disk_usage_last_updated=now(),file_size=? where ref=?",array("i",$total,"i",$rsize,"i",$resource));
    return 
true;
    }

This article was last updated 3rd October 2022 12:05 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.