get_dirsize

Get the size of a directory.

Description

(int) get_dirsize( (string) $directory ); 

A helper function that is used primarily to check whether a blog has exceeded its allowed upload space.

Returns (int)

Size of the directory in MB.

Parameters (1)

0. $directory (string)
Full path of a directory.

Usage

  1. if ( !function_exists( 'get_dirsize' ) ) { 
  2. require_once ABSPATH . WPINC . '/ms-functions.php'; 
  3.  
  4. // Full path of a directory. 
  5. $directory = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_dirsize($directory); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/ms-functions.php  
  1. function get_dirsize( $directory ) { 
  2. $dirsize = get_transient( 'dirsize_cache' ); 
  3. if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) 
  4. return $dirsize[ $directory ][ 'size' ]; 
  5.  
  6. if ( ! is_array( $dirsize ) ) 
  7. $dirsize = array(); 
  8.  
  9. // Exclude individual site directories from the total when checking the main site,  
  10. // as they are subdirectories and should not be counted. 
  11. if ( is_main_site() ) { 
  12. $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory, $directory . '/sites' ); 
  13. } else { 
  14. $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory ); 
  15.  
  16. set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); 
  17. return $dirsize[ $directory ][ 'size' ];