Changeset 5964

Show
Ignore:
Timestamp:
08/28/07 23:13:16 (1 year ago)
Author:
ryan
Message:

Take post_max_size into account when determining the upload limit. Props mdawaffe. fixes #4240

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/includes/template.php

    r5927 r5964  
    560560} 
    561561 
     562function wp_convert_hr_to_bytes( $size ) { 
     563    $size = strtolower($size); 
     564    $bytes = (int) $size; 
     565    if ( strpos($size, 'k') !== false ) 
     566        $bytes = intval($size) * 1024; 
     567    elseif ( strpos($size, 'm') !== false ) 
     568        $bytes = intval($size) * 1024 * 1024; 
     569    elseif ( strpos($size, 'g') !== false ) 
     570        $bytes = intval($size) * 1024 * 1024 * 1024; 
     571    return $bytes; 
     572} 
     573 
     574function wp_convert_bytes_to_hr( $bytes ) { 
     575    $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' ); 
     576    $log = log( $bytes, 1024 ); 
     577    $power = (int) $log; 
     578    $size = pow(1024, $log - $power); 
     579    return $size . $units[$power]; 
     580} 
     581 
    562582function wp_import_upload_form( $action ) { 
    563     $size = strtolower( ini_get( 'upload_max_filesize' ) ); 
    564     $bytes = 0; 
    565     if (strpos($size, 'k') !== false) 
    566         $bytes = $size * 1024; 
    567     if (strpos($size, 'm') !== false) 
    568         $bytes = $size * 1024 * 1024; 
    569     if (strpos($size, 'g') !== false) 
    570         $bytes = $size * 1024 * 1024 * 1024; 
    571     $size = apply_filters( 'import_upload_size_limit', $size ); 
     583    $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); 
     584    $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); 
     585    $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes ); 
     586    $size = wp_convert_bytes_to_hr( $bytes ); 
    572587?> 
    573588<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>"> 
    574589<p> 
    575590<?php wp_nonce_field('import-upload'); ?> 
    576 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>
     591<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>
    577592<input type="file" id="upload" name="import" size="25" /> 
    578593<input type="hidden" name="action" value="save" />