Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Silverstripe version 3.1.9 Max file size?


Go to End


2 Posts   1610 Views

Avatar
KatB

Community Member, 105 Posts

7 March 2017 at 1:58pm

A user uploaded an image that was slightly larger than 8MB into a folder under the Files tab. Both upload_max_filesize and post_max_size were set to 32M now 64MB. This resulted in the user now longer being able to access that Folder through Silverstripe. The entry in the database table appears to be fine. The file uploaded fine and could be downloaded via FTP fine.

I removed that folder and tried to upload the image as part of a specialised page. The image does not upload.
I can't see the image on the server, though I do see a listing in the database table. The CMS refuses to navigate the page 3 where that file should be listed.

What could be going on?

*Yes, I realise 8MB is large for a photo. And isn't ideal. I can manually correct this myself. However, in future instances, how do I let the users do what they want to do? They may actually have good cause for posting such a large image. Is there a file size limit?

Avatar
Vix

Community Member, 60 Posts

8 March 2017 at 9:58pm

Hi Kat

If you check out the docs on the Upload field (https://docs.silverstripe.org/en/3/developer_guides/forms/field_types/uploadfield/) you will see some of the stuff you can do with uploads.

You can setAllowedMaxFileSize() on an upload field on each instance you wish to apply it, or add some options to your _config.yml file to apply globally.

Example from the upload field docs page is
_config.yml

Upload_Validator: 
      default_max_file_size: 
        '[image]': '1m'
        '[doc]': '5m'
        'jpeg': 2000

Or an individual upload field might look like

function getCMSFields() {
    $fields = parent::getCMSFields(); 
    $upload = new UploadField('MyFile', 'My File Title');
    $sizeMB = 2; // 2 MB
    $size = $sizeMB * 1024 * 1024; // 2 MB in bytes
    $upload->getValidator()->setAllowedMaxFileSize($size);
    $fields->addFieldToTab("Root.MyTab", $upload);
    return $fields;
}