ukash - ucuz ukash kart -
Wednesday, 18 August 2010 05:48

How to Force Users to Login before Downloading K2 Item Attachments

One of the great uses that K2 (Joomla Component) claims that their system can do is act as a download manager. However, it does not have the ability to restrict downloads to only logged-in users. I needed a system where we could display the K2 item, with a preview and description, but not actually let them download the attachments. This was not achievable using just the included K2 parameters / settings, so I made this hack:

LOOK IN THIS FILE:
/com_k2/templates/templatename/item.php (line 364)

Download the attachment (below) (Item.php K2 Template Modification Code) for the actual changes you need to make.

(note: stock, this will appear in your K2 component folder (/components/com_k2). You SHOULD be creating a template override (/templates/yourtemplate/html/) using the technique described here.

Nate Covington

Nate Covington

I work with advertising agencies and marketing consultants, as well as directly with business owners to build streamlined, effective web sites. The large majority of my projects are built using Joomla, although I also support Wordpress, Drupal, OSCommerce, and almost any other open-source platform.  If you are interested in hiring me, please use my "Get a Quote" form.

Website: www.covingtoncreations.com E-mail: This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Comment subscription

Receive email notification when a new comment is added to this item.

11 comments

  • Comment Link Mike Soden Sunday, 22 January 2012 20:51 posted by Mike Soden

    Hi Nate,

    thanks for documenting this! I'm trying to implement this on K2 v2.4.1, but the attachment you've submitted seems like it's for a different version of K2 (k2_mod_content_default.php). Is this supposed to replace (or template override) item.php?

    Can you clarify?

    thanks again,

    Mike

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link ben Friday, 16 December 2011 23:13 posted by ben

    wrong. users can still copy the link once logged in and passed it on , k2 will allow you to download if you are not loged in , I implemented a hack that requires specific gid in order to download

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link Nate Covington Tuesday, 06 September 2011 06:51 posted by Nate Covington

    @Mark - Correct, if you need a truly 'secure' file system, look into the DocMan component. It stores its files outside of your "public" directory so that people cannot guess file names...

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link Mark Monday, 05 September 2011 10:33 posted by Mark

    Hi,
    I have been looking for a method to restrict the download of an attachment within a K2 item which is restricted. Your mod is to restrict the download in an unrestricted item. But if the user knows the actual url of the file then your system will not block this? I know for example that this is the case with a user restricted item with attachments.

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link T Friday, 05 August 2011 21:57 posted by T

    Nicely done my friend. This is a needed function of K2. Make sure you create your template override. It's seems to be key.

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link Rohit Tuesday, 26 April 2011 17:54 posted by Rohit

    Hey thanks!! this worked like a charm!!

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link adeola Monday, 11 April 2011 10:06 posted by adeola

    I am using the default template.

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link Nate Covington Monday, 11 April 2011 07:04 posted by Nate Covington

    Post your (relevant) code here?

    Also are you using the "default" K2 category? Or did you make a new one? If new, did you assign via category parameters?

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link Adeola Saturday, 09 April 2011 17:15 posted by Adeola

    i modified the default template under com_k2

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it
  • Comment Link Nate Covington Friday, 08 April 2011 07:10 posted by Nate Covington

    What file did you modify? Are you using the templates in the normal /components/ location, or did you create an override?

    if you created a new K2 template, did you assign it via the category parameters?

    This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Add comment


About the Author

Around the Joomla Community

JoomlaMarketing.org is not affiliated with or endorsed by the Joomla! Project.