Jump to content

Download area with download counter?


ShadowByte
 Share

Recommended Posts

Hello everyone,
I would like to create a download area where I can, for example. pdf, zip, rar, odt files can be offered for download.
Downloads should also be counted if possible.
Is there a possibility? Does anyone have an idea for me?

Thanks in advance


Greetings

Link to comment
Share on other sites

I’ve never tried myself, but I assume you could achieve this using the “PagefileSecure” option in your template holding the files:

1589513953_Screenshot2024-02-03at10_30_57.thumb.png.d064888f8893d01b00af430ebb5659d3.png

Which would then allow you to hook into ProcessPageView::sendFile:

$wire->addHookAfter("ProcessPageView::sendFile", function(HookEvent $event) {
	/** @var Page $page */
	$page = $event->arguments("page");
	if($page->template == 'admin') return;
	/** @var Pagefile $file */
	$file = $page->filesManager()->getFile($event->arguments("basename"));
	$page->of(false);
	$count = (int) $file->filedata("downloadsCount");
    $file->filedata("downloadsCount", ++$count);
	$page->save();
});

And then later on retrieve and display the downloads count.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...