Ignore:
Timestamp:
Aug 20, 2014 11:56:27 AM (10 years ago)
Author:
anonymous
Message:

Added Validator::fileUploadSize(), phpIniGetBytes(), and fixed php version error checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r486 r487  
    503503}
    504504
     505/*
     506* Convert a php.ini value (8M, 512K, etc), into integer value of bytes.
     507*
     508* @access   public
     509* @param    string  $val    Value from php config, e.g., upload_max_filesize.
     510* @return   int             Value converted to bytes as an integer.
     511* @author   Quinn Comendant <quinn@strangecode.com>
     512* @version  1.0
     513* @since    20 Aug 2014 14:32:41
     514*/
     515function phpIniGetBytes($val)
     516{
     517    $val = trim(ini_get($val));
     518    if ($val != '') {
     519        $last = strtolower($val{strlen($val) - 1});
     520    } else {
     521        $last = '';
     522    }
     523    switch ($last) {
     524        // The 'G' modifier is available since PHP 5.1.0
     525        case 'g':
     526            $val *= 1024;
     527        case 'm':
     528            $val *= 1024;
     529        case 'k':
     530            $val *= 1024;
     531    }
     532
     533    return (int)$val;
     534}
     535
    505536/**
    506537 * Tests the existence of a file anywhere in the include path.
Note: See TracChangeset for help on using the changeset viewer.