Limit User Downloads - php

I have a website which has multiple downloadable videos, Im after a way of limiting the amount of files any user can download at any one time, Currently all users can download all files at once, which is killing speed!
So need to limit to say x2 downloads at once! Is this done in the .htaccess or via php
Thanks

In your download php script make a entry in database table when user hit download process.
As a number of count download hide download button.

Related

Wordpress Cron Job to download files

I am using pitch print to get customers to edit business cards through a woocommerce set up. When the order is created a link gets appended to the order for the admin/shop manager to download the rendered pdf.
The pdf is stored on the pitch print server, I believe via s3, and you need a signature/key to access the file. Which is ordinarily installed on the plugin admin.
I would like to set up a cron to automatically download the file, either when the order is created, or happy to settle for a times interval.
Post a comment for more clarification if needed.
Cheers
Andrew

Serving files for download with PHP - Stop multiple clicks

I've got a "download.php" script which serves up files for download and the user can choose to download a ZIP file which is custom to them.. so needs to be generated on the fly.
The problem I've got, is if the user clicks the ZIP file 5 times in quick succession, the ZIP is generated 5 times on the server.
I need a method to only generate this on the first click, and not keep generating over and over again.
I do not want to "disable" the link permanently, because downloading the file again a few minutes later is fine if the user wants to, I just want to try and stop a malicious user hammering the download script to generate ZIPs constantly using server processing power.
Any ideas? I've been trying for hours and can't seem to get a solution which works :/
Thanks
Is it an option to include a captcha code or similar to activate the download? That would stop the fast clicking.
Add jQuery to the front page to disable the button after the first click. Something like:
$("#button").click(fuction(e) {
$(this).attr("disabled", "");
});
Also, you could cache the zip files for a certain amount of time so their only processed once for a thirty minute block, or some time frame.

Limiting the number of times a link is clicked

I need to limit the number of times a pdf is downloaded by people (to 500). Ideally it would count the clicks to 500 and then remove the link. It has just occurred to me that I will also need to stop each person clicking more than once. Basically I have been asked to allow the first 500 people download a file and then end it. PHP or javascript would be prefered (its on a wordpress site)
regards
Rich
You don't wanna limit the number of times a link can be clicked, you want to limit the number of times that particular link returns a PDF file.
In other words, your link shouldn't point directly to the requested resource (the PDF), but to a PHP file that can assert that the file hasn't been downloaded more than 500 times.
Here's an example of how to output files outside your www directory to the browser.
Link to a PHP script that will control the access and serve the PDF if allowed (example with readfile(). Use the $_SESSION to manage how many times a single user has downloaded - update a value after downloading.
Use a database table or other data source to count the total downloads so that when it reaches 500, you can deny all access to the PDF.
To expand on Sherlock's solution, you want to hide your PDF behind a PHP file. When I say hide, I mean placing it in a place that is not accessible directly: consider moving it out of your "www root" or using a .htaccess to prevent accessing the file directly. Most advanced users will figure out how to access your PDF if the document is guessable and publicly available.
Your PHP should simply do the following:
Check if the document has been downloaded less than 500 times OR the user's IP has "unlocked access" to the document (you might want to allow a "window" during which a user can download again the document - some people will open the file when they actually want to save it, and don't know how to save to disk from their reader) - otherwise display an error
Store the IP address of the user for this document
Send the appropriate header for the file type: header('Content-type: application/pdf');
Send the file name: header('Content-Disposition: attachment; filename="the document.pdf"');
Send the file content: readfile($pathToPDF);

How do I show a link once a file is uploaded

I had trouble finding an answer for this problem. I would like to display a link to a page that has a video file on it but I don't want the link to appear until after the video file is uploaded.
It's a site where users upload videos so I don't want to have to manually put the links there for them after they upload their videos, nor do I want to make the links ahead of time since users will click them and there will be no video available.
So, is there a way to keep a link hidden until a file is uploaded. Once the file is uploaded the php page where the link will be on checks to see if it exists and then if it does the link is shown, otherwise the link stays hidden.
Each time the form that the client uses to upload a file is sent store the information of the file in a database.
Each time the client request the list of videos, query the database and build the web page based on the results.
Make sure to associate the uploaded files to the users, so you don't mix the up. Are you managing authentication already?
If you want to have the links appear as soon as the upload is finished without reloading the page, then you need ajax.

HTML5 File Upload (How to select multiple files in Single browse click)

I am looking for a jquery plugin with no ajax upload, the only feature that i am looking for is allowing the user to select multiple files after clicking browse, and not limited to choose one file in a single browse?
I have tried multi file upload http://www.fyneworks.com/jquery/multiple-file-upload/
but the user should browse for each file separately; i.e users are not able to select multiple files at the same time?
Any recommendations?
You can have a look at the Fluid Infusion Uploader. The online demo is here. For more details, have a look at the API documentation.

Categories