Summer Sale! All accounts are 50% off this week.

tareenmj's avatar

How do I change the max_post_size and the max_upload_size in Laravel 5.0?

I need to be able to upload files my user choses to upload. I was able to accomplish this, thanks to Laravel's filesystems but I am unsure about what is the max size the user can upload, and how I can change this property. Could anyone help me out?

0 likes
4 replies
JackJones's avatar

I use this in a particular class

class PHPSettings {

    public function getPhpMaxUploadFileSize($format = 'K', $decimals = 0)
    {
        $max = ['upload' => $this->parseFileSizes(ini_get('upload_max_filesize'), $format, $decimals),
                'post' => $this->parseFileSizes(ini_get('post_max_size'), $format, $decimals)];

        if($max['upload'] < $max['post'])
            return $max['upload'];

        return $max['post'];
    }


    public function parseFileSizes($input, $format = 'K', $decimals = 0)
    {
        $input = strtoupper($input);

        $number = preg_replace('/[^0-9]/', '', $input);
        $letter = preg_replace('/[^BKMGT]/', '', $input);

        if($letter)
            return round($number * pow(1024, strpos('BKMGT', $letter[0]) - strpos('BKMGT', $format[0])), $decimals);

        return round($number, $decimals);
    }
}

$fs = new PHPSettings;
echo $fs->getPhpMaxUploadFileSize();

Not sure if that's of any use to you, you'd need to change your ini settings to increase the upload size

tareenmj's avatar

@JackJones yea but I can't seem to locate the file where I would change the upload_size, or can I just do it on a route. I read that php has a php.ini file but i can't find it on my Laravel app

JackJones's avatar

PHP.ini will be inside your PHP directory, it has nothing to do with Laravel

In my case it is xampp\PHP\php.ini, but yours will be where you installed it to

You'll need to restart after you change the value

Snapey's avatar

its in the php configuration not in your laravel app.

if you put dd(phpinfo()); in a route and then hit that route, your current php configuration will be displayed.

Near the top of that file is Configuration File (php.ini) Path This will tell you where the .ini file is located so that you can change it.

This is not part of your Laravel install so you need to do this locally and on production servers.

Please or to participate in this conversation.