Support

Account

Home Forums Backend Issues (wp-admin) Overwrite max upload file site with ACF custom field (or just file field)

Solved

Overwrite max upload file site with ACF custom field (or just file field)

  • I always got the complained that clients sites were slow, and than when I check the site I saw that they were uploading 13mb images for every post. Now to fix this I set an overall limit of 300kb for images and this seems to be fine, but when a site needs .pdf files the 300kb limit is a bit to strict.

    I set this upload limit with my own plugin and it is for the whole site. Now what I was thinking was would it be possible to overwrite this limit with a custom field in ACF so that if I place a ‘file’ field the upload limit is the one that I set in the ACF interface.

    TL;DR How to set a site wide upload limit of 300kb, but overwrite (increase) this only for the ACF custom file field.

  • You can’t decrease the php setting and also allow a specific file type to be larger. What you need to do is to set the size to the max you want to allow for the PDF files and then create an upload filter that will limit the file size of other file types. I found an example of doing this based on user role, but this could be modified to base the max size on file type instead with a little work. https://gist.github.com/unfulvio/1ee103a6f86893771b5a

  • @hube2 thanks this seems like a solution.

    I thought maybe ACF had some hooks to check if the upload is going through a file field and than you could set the max upload to the ACF max upload size on the file and else set a default, something like this https://gist.github.com/mvaneijgen/4db072899ae54ef7469519b50f5ddacc but maybe that is just wishful thinking.

    Thanks again.

  • The field setting can only be used to lower the max size set with PHP. If the file is larger than the max size set in php then php will refuse to upload the files before it even gets as far as WP. WP is just detecting the error condition of the file set by PHP.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Overwrite max upload file site with ACF custom field (or just file field)’ is closed to new replies.