Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file is too big? #2394

Closed
ash0080 opened this issue Mar 2, 2019 · 24 comments
Closed

file is too big? #2394

ash0080 opened this issue Mar 2, 2019 · 24 comments

Comments

@ash0080
Copy link
Contributor

ash0080 commented Mar 2, 2019

2019-03-02 15 17 32
2019-03-02 16 01 05
2019-03-02 16 04 15
2019-03-02 16 34 21

is this a bug or my mistake?

@axel-rank
Copy link

Where do you upload? In admin? In frontend form?
Check form plugin setting: max filesize.

@ash0080
Copy link
Contributor Author

ash0080 commented Mar 2, 2019

in admin

@ash0080
Copy link
Contributor Author

ash0080 commented Mar 10, 2019

any tips?

@rhukster
Copy link
Member

There's a grav config in system: grav.config.system.media.upload_limit

@axel-rank
Copy link

I cannot set this in admin plugin? Why?
In my usr/config/system.yaml the value for media upload_limit is: 2097152. ???
Is this the standard setting?

@ash0080
Copy link
Contributor Author

ash0080 commented Mar 12, 2019

屏幕快照 2019-03-12 10 49 03
seems the config is 1G, but the limit is still 256Mb, a bug?

@rhukster
Copy link
Member

Actually the system media.upload_limit option has been removed, even though there's still some places in the code that uses it if set. There is still a reference in forms for via files.filesize, this defaults to 0 unlimited, but it's possible you have this set?

@axel-rank
Copy link

Still documented as if I could set this in admin panel:

admin

@rhukster
Copy link
Member

Ok, I've dug into this quite a bit and it gets complicated....

First we had a setting system.media.upload_limit, then we had various options in form config like form.files.filesize as well as some admin plugin limits I can't recall. Not to mention the default PHP values for post_max_size and upload_max_filesize. These were all used in various places, but ultimately the PHP values are the hard-stop-limits.

Back in October of 2017 (Grav 1.3.7), this was simplified by removing the actual option for system.media.upload_limit, creating a method in Utils to get the system PHP values, and overriding any existing configuration settings for system.media.upload_limit with the smallest value provided by PHP settings. It was done this way to minimize the impact of changing the functionality mid-release cycle, so the old value could still be used, by plugins (admin, form, etc) but would use PHP provided values.

In the Grav 1.6 branch, I've now cleaned this up and completely removed all references to system.media.upload_limit and explicitly used the Utils::getUploadLimit() function to make this clearer going forward. Admin and Forms plugins have also been updated in their respective RC branches in the same way.

I'm testing all this with Grav 1.6, so there well may have been other fixes between this and Grav 1.5, but as I'm trying to get 1.6 out ASAP, I'm putting my focus there and not in 1.5 at the mo.

The basic rules are:

  1. In Admin plugin, the filesize limit in File and PageMedia fields is limited by the PHP settings alone.
  2. In Form plugin, the filesize limit in File field is limited by the field setting of filesize: if set, then the form.file.filesize if set and not 0, then the PHP settings.

I'm sure this will all be sorted when Grav 1.6 is released.

@lorddoumer
Copy link

after updating to 1.6 today file upload in the admin panel doesn't work anymore: despite the maximum filesize is set to 2048M in the php.ini, which also the info-tab recognices, when trying to upload a file I get a NEGATIVE maximum file size;
screenshot
how to fix this? never had any problem with 1.5

@rhukster
Copy link
Member

rhukster commented Apr 13, 2019

Strange one, might need to get a copy of you php.ini and your Grav system.yaml

Also, what is the file you are uploading? Perhaps i can get a copy of that to try to replicate?

@rhukster
Copy link
Member

Also is this with a Page media upload or some custom form you have?

@lorddoumer
Copy link

lorddoumer commented Apr 14, 2019

Ah, page media sorry not to mention it - form would be easy because there is an option for the upload size (page media worked with 1.5 also without problems when there was the option for it). The file is just a jpg (1920x1440px, 450kb - 850kb, the one from the screenshot was 740kb), server is apache with php 7.2 fpm - please find attached the ini and yaml, please let me know if you need anything else.

php.ini.txt
system.yaml.txt

@rhukster
Copy link
Member

@lorddoumer if you inspect you can fire up your browser developer tools, and inspect the Page Media element, you should see this <div id="grav-dropzone"></div> element. In there is a data-dropzone-options that contain some settings. One of those is the maxFilesize in megabytes. What does yours look like?

Image 2019-04-14 at 8 58 53 PM

@lorddoumer
Copy link

Yes, there it is - and it has the same strange value:
screenshot

Where does this coem from?

@rhukster
Copy link
Member

I think it has something to do with the rounding logic. can you try replacing the Utils::parseSize() function with this:

    public static function parseSize($size)
    {
        $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); 
        $size = preg_replace('/[^0-9\.]/', '', $size);
        if ($unit) {
            return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
        } else {
            return round($size);
        }
    }

@lorddoumer
Copy link

@rhukster that's it, upload working fine again, thanks! :)

@rhukster
Copy link
Member

Sweet, should be in the next release later today.

@prismplex
Copy link

prismplex commented May 1, 2019

Still having the same issues with Grav 1.6.8 and PHP 7.3
Tried also with a newly installed Grav, so I think the problem is maybe somewhere at my end. Should I take care about a special php setting beside upload_max_filesize or post_max_size?
Thank you in advance!

upload
grav-dropzone

@rhukster
Copy link
Member

rhukster commented May 1, 2019

What values do you have set for those in php.ini?

@prismplex
Copy link

upload_max_filesize 16G
post_max_size 0

@rhukster
Copy link
Member

rhukster commented May 1, 2019

I just can't replicate what you are seeing with those values. I get "maxFilesize":0

Can you try changing your values to sane ones? like:

upload_max_filesize = 256M
post_max_size = 512M

Does that fix things? or do you still get weird negative numbers?

@rhukster
Copy link
Member

rhukster commented May 1, 2019

Another thing to try. In user/plugins/form/classes/Form.php, replace the getMaxFilesize() method with this:

    public static function getMaxFilesize($mbytes = false)
    {
        $config = Grav::instance()['config'];

        $system_filesize = 0;
        $form_filesize = $config->get('plugins.form.files.filesize', 0);
        
        $upload_limit = Utils::getUploadLimit();
        if ($upload_limit > 0) {
            $system_filesize = intval($upload_limit / static::BYTES_TO_MB);
        }

        if ($form_filesize > $system_filesize || $form_filesize === 0) {
            $form_filesize = $system_filesize;
        }

        if ($mbytes) {
            return $form_filesize * static::BYTES_TO_MB;
        }

        return $form_filesize;
    }

See if that helps?

@prismplex
Copy link

Thank you!
The modded function did not work, but I changed the value of post_max_size from 0 to 512M. Now it is working perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants