Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Last active November 22, 2016 03:19
Show Gist options
  • Save cuonghuynh/0e9c1937e6c68c71e2e2d592544f3370 to your computer and use it in GitHub Desktop.
Save cuonghuynh/0e9c1937e6c68c71e2e2d592544f3370 to your computer and use it in GitHub Desktop.
Function helper to get max file upload size in Bytes
<?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