Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

update_disk_usage()

Parameters

ColumnTypeDefaultDescription
$resource

Location

include/resource_functions.php lines 6069 to 6096

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=(int) 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 19th March 2024 11:35 Europe/London time based on the source file dated 11th March 2024 14:25 Europe/London time.