limit upload size to site's available limit, see #12853

git-svn-id: https://develop.svn.wordpress.org/trunk@14420 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ron Rennick 2010-05-03 22:40:02 +00:00
parent d2b4e092aa
commit e35e6165ab
2 changed files with 22 additions and 5 deletions

View File

@ -399,11 +399,28 @@ function is_upload_space_available() {
if ( get_site_option( 'upload_space_check_disabled' ) )
return true;
$space_allowed = get_space_allowed();
if ( !( $space_allowed = get_upload_space_available() ) )
return false;
return true;
}
function upload_size_limit_filter( $size ) {
return min( $size, get_upload_space_available() );
}
/**
* Determines if there is any upload space left in the current blog's quota.
*
* @return int of upload space available in bytes
*/
function get_upload_space_available() {
$space_allowed = get_space_allowed() * 1024 * 1024;
if ( get_site_option( 'upload_space_check_disabled' ) )
return $space_allowed;
$dir_name = trailingslashit( BLOGUPLOADDIR );
if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) )
return true;
return $space_allowed;
$dir = dir( $dir_name );
$size = 0;
@ -418,12 +435,11 @@ function is_upload_space_available() {
}
}
$dir->close();
$size = $size / 1024 / 1024;
if ( ( $space_allowed - $size ) <= 0 )
return false;
return 0;
return true;
return $space_allowed - $size;
}
/**

View File

@ -45,6 +45,7 @@ add_filter( 'wp_upload_bits', 'upload_is_file_too_big' );
add_filter( 'import_upload_size_limit', 'fix_import_form_size' );
add_filter( 'upload_mimes', 'check_upload_mimes' );
add_action( 'admin_notices', 'ms_deprecated_blogs_file' );
add_action( 'upload_size_limit', 'upload_size_limit_filter' );
// Mail
add_filter( 'wp_mail_from', 'wordpressmu_wp_mail_from' );