get_upload_space_available example


    protected function check_upload_size( $file ) {
        if ( ! is_multisite() ) {
            return true;
        }

        if ( get_site_option( 'upload_space_check_disabled' ) ) {
            return true;
        }

        $space_left = get_upload_space_available();

        $file_size = filesize( $file['tmp_name'] );

        if ( $space_left < $file_size ) {
            return new WP_Error(
                'rest_upload_limited_space',
                /* translators: %s: Required disk space in kilobytes. */
                sprintf( __( 'Not enough space to upload. %s KB needed.' )number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ),
                array( 'status' => 400 )
            );
        }

        
return $file;
    }

    if ( $file['error'] > 0 ) { // There's already an error.         return $file;
    }

    if ( defined( 'WP_IMPORTING' ) ) {
        return $file;
    }

    $space_left = get_upload_space_available();

    $file_size = filesize( $file['tmp_name'] );
    if ( $space_left < $file_size ) {
        /* translators: %s: Required disk space in kilobytes. */
        $file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' )number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
    }

    if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
        /* translators: %s: Maximum allowed file size in kilobytes. */
        $file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' )get_site_option( 'fileupload_maxk', 1500 ) );
    }

    
/** * Determines if there is any upload space left in the current blog's quota. * * @since 3.0.0 * @return bool True if space is available, false otherwise. */
function is_upload_space_available() {
    if ( get_site_option( 'upload_space_check_disabled' ) ) {
        return true;
    }

    return (bool) get_upload_space_available();
}

/** * Filters the maximum upload file size allowed, in bytes. * * @since 3.0.0 * * @param int $size Upload size limit in bytes. * @return int Upload size limit in bytes. */
function upload_size_limit_filter( $size ) {
    
Home | Imprint | This part of the site doesn't use cookies.