Last active
November 22, 2016 03:19
-
-
Save cuonghuynh/0e9c1937e6c68c71e2e2d592544f3370 to your computer and use it in GitHub Desktop.
Function helper to get max file upload size in Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Infrastructure\Utilities; | |
class SystemUtil | |
{ | |
public static function maxFileUploadSize() | |
{ | |
//select maximum upload size | |
$maxUpload = self::getBytes(ini_get('upload_max_filesize')); | |
//select post limit | |
$maxPost = self::getBytes(ini_get('post_max_size')); | |
//select memory limit | |
$memoryLimit = self::getBytes(ini_get('memory_limit')); | |
// return the smallest of them, this defines the real limit | |
return min($maxUpload, $maxPost, $memoryLimit); | |
} | |
public static function getBytes($val) | |
{ | |
$val = trim($val); | |
$last = strtolower($val[strlen($val)-1]); | |
switch($last) | |
{ | |
case 'g': | |
$val *= 1024; | |
case 'm': | |
$val *= 1024; | |
case 'k': | |
$val *= 1024; | |
} | |
return $val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment