How to project file download button?

Hi

I have file uploaded to site using the Core file plugin. The files are public accessible to every one. I want to user to login in order to download the file.

Visitor will be able to see the page and download button but after download button click he should get message that Person needs to login for downloading file.

  • If you override the view mod/file/views/default/resources/file/view.php with a modified version where you enclose the registered of the download title menu button with

    if (elgg_is_logged_in()) {
        elgg_register_menu_item('title', array(
            'name' => 'download',
            'text' => elgg_echo('download'),
            'href' => elgg_get_download_url($file),
            'link_class' => 'elgg-button elgg-button-action',
        ));
    }

    only users who are logged-in to your site will see the download button whereas logged-out visitors will only see the file (as long as its access level is public) but don't see the download button.

    Learn how to override views: http://learn.elgg.org/en/stable/guides/views.html#overriding-views. That's better than modifying the file plugin file in the long run.

     

  • Thanks for pointers.

    I am working on Elgg project (A Community Site of my own). This helped me get my hands dirty with Elgg.

    I have converted the requirement to Elgg plugin. So people can install the plugin instead of changing Core file. Below is plugin link

    https://elgg.org/plugins/2958220