WordPress at a glance

get_dirsize() WP 1.0

Get the size of a directory.

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

Works based on: recurse_dirsize()

No Hooks.

Return

Int. Size of the directory in MB.

Usage

get_dirsize( $directory );
$directory(string) (required)
Full path of a directory.

Code of get_dirsize: wp-includes/ms-functions.php VER 4.9.8

<?php
function get_dirsize( $directory ) {
	$dirsize = get_transient( 'dirsize_cache' );
	if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) )
		return $dirsize[ $directory ][ 'size' ];

	if ( ! is_array( $dirsize ) )
		$dirsize = array();

	// Exclude individual site directories from the total when checking the main site,
	// as they are subdirectories and should not be counted.
	if ( is_main_site() ) {
		$dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory, $directory . '/sites' );
	} else {
		$dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory );
	}

	set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
	return $dirsize[ $directory ][ 'size' ];
}

Related Functions

From tag: File system (create delete files folders)

More from category: Multisite

No comments
    Hello, !     Log In . Register