WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/21/2020 03:19:58 PM (6 months ago)
Author:
whyisjake
Message:

Site Health: Include new tests to check for the ability to upload files.

Several new checks:

  • max_file_uploads
  • file_uploads
  • post_max_size
  • upload_max_filesize
  • upload_max
  • max_file_uploads

In addition, new function parse_ini_size() that converts shorthand byte strings to bytes. Useful for size comparisons.

Fixes #50038.
Props dd32, donmhico, JavierCasares, SergeyBiryukov, ayeshrajans, Clorith, ipstenu, sabernhardt, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r48473 r48535  
    475475
    476476    return false;
     477}
     478
     479/**
     480 * Converts a shorthand byte string to bytes.
     481 *
     482 * Useful when needing to compare two byte strings for size differences.
     483 *
     484 * E.g.
     485 *  "1G" (1 Gigabyte) = 1073741824
     486 *  "10M" (10 Megabytes) = 10485760
     487 *  "1K" (1 Kilobyte) = 1024
     488 *
     489 * @since 5.5.0
     490 *
     491 * @param  string $size_string Shorthand byte string
     492 * @return int                 $size_string converted to numberic bytes.
     493 */
     494function parse_ini_size( $size_string ) {
     495    $size_string = trim( $size_string );
     496    $last        = strtolower( substr( $size_string, - 1 ) );
     497    $value       = intval( $size_string );
     498
     499    switch ( $last ) {
     500        case 'g':
     501            return (int) $value * GB_IN_BYTES;
     502        case 'm':
     503            return (int) $value * MB_IN_BYTES;
     504        case 'k':
     505            return (int) $value * KB_IN_BYTES;
     506        default:
     507            return (int) $value;
     508    }
    477509}
    478510
Note: See TracChangeset for help on using the changeset viewer.