This website uses cookies to improve your experience and deliver relevant information.

on Monday, 09 January 2012

K2 attachments give 404 error on downloading with 2.5.x

We had a client report that their attachments on K2 articles would not download - giving an error message in the source code initially, and then subsequently a 404 error. On investigating we identified that the latest version of K2 handles attachments slightly differently.


The problem arose because we make extensive use of template override files - a great way of changing the way a page looks without hacking the core of components, but in the case where core elements of the component are changed (such as in the upgrade to K2 2.5.x) the template overrides need to be updated too!

Updating template overrides is pretty easy if you know what part of the file you need to update, and what you need to replace it with. In this case we need to edit the item.php file, which controls how the individual item pages are displayed. This can be found in templates>yourtemplate>html>com_k2>templates>yourtemplatename.

What needed to be done was changing the attachments block to reflect the new way of managing attachements, as below:

<div class="itemAttachmentsBlock">
<span><?php echo JText::_('K2_DOWNLOAD_ATTACHMENTS'); ?></span>
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<a title="<?php echo htmlentities($attachment->titleAttribute, ENT_QUOTES, 'UTF-8'); ?>" href="/<?php echo $attachment->link; ?>">
<?php echo $attachment->title ; ?>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo (count($attachment->hits)==1) ? JText::_('K2_DOWNLOAD') : JText::_('K2_DOWNLOADS'); ?>)</span>
<?php endif; ?>
<?php endforeach; ?>


We're specialists in Content Management Systems Want to work with the experts?

Virya Group provides a range of solutions to your technology needs