How to Change K2’s Maximum Upload Size

We can never praise K2 enough – we think it handles content even better than Joomla (we did write a post about its advantages). It’s not perfect though, and it does, occasionally, suffer from some inconsistencies.

For example, if you’re editing an item in K2, and you scroll down to the bottom of the editor, and then you click on the Image button, then you’ll notice that the maximum upload size of the image is the same as that of Joomla (which is set at the Media Manager level).

However, if you click on the Image tab on the top, you will notice that the Max upload size is set to the maximum upload limit defined in your global php.ini (for many servers, that maximum upload limit is typically set to 2 MB). If you want proof about this, then open the file default.php located under the administrator/components/com_k2/views/item/tmpl folder and check line 242:

<i>(<?php echo JText::_('K2_MAX_UPLOAD_SIZE'); ?>: <?php echo ini_get('upload_max_filesize'); ?>)</i>

As you can see from the above line, K2 is setting the maximum upload size to the upload_max_filesize configuration setting in the global php.ini.

The above also applies to the maximum upload limit for media files (under the Media tab).

So, how to address this problem?

Addressing this problem is easy if you are on a VPS or on a dedicated server. All you need to do is to create a file called .user.ini with the following content…

upload_max_filesize = "256M"
post_max_size = "256M"

…and then upload it to the root directory of your website.

Once this is done, K2’s maximum upload will increase to a whopping 256 Megabytes! (If you want more than 256 Megabytes, then all you need to is to change the number in the .user.ini file from 256 to a higher number of your choice). If you are on a shared hosting environment, then some companies won’t allow the override of certain PHP settings through .user.ini files – in this case it is a good idea to contact your host and ask them to increase the limit for your website (some hosts will acquiesce to such requests).

We hope that in future iterations, K2 will address the problem and the maximum upload limit (across the board) will be the same as Joomla’s. Meanwhile, you can rely on the solution above to fix the problem (the best thing about it is that you won’t have to modify a single K2 file!).

If you need help implementing the above solution, then all you need to do is to contact us. Our price is right, our work is professional and quick, and we are the friendliest programmers on the Milky Way.

No comments yet.

Leave a comment