Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

update_disk_usage()

Parameters

ColumnTypeDefaultDescription
$resource

Location

include/resource_functions.php lines 5234 to 5263

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 sql_value("SELECT file_extension value FROM resource where ref = '" escape_check($resource) . "' AND file_path IS NULL",'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);
            
#echo "<br/>-". $f . " : " . $s;
            
$total+=$s;
            }
        }
    
#echo "<br/>total=" . $total;
    
sql_query("update resource set disk_usage='$total',disk_usage_last_updated=now(),file_size='$rsize' where ref='" escape_check($resource) . "'");
    return 
true;
    }

This article was last updated 11th July 2020 02:05 Europe/London time based on the source file dated 10th July 2020 16:06 Europe/London time.