PHP – Limits the number of times a file can be downloaded

Limits the number of times a file can be downloaded… here is a solution to the problem.

Limits the number of times a file can be downloaded

I’m creating a website where people can create their own videos and download them from my server.

I want to limit the number of downloads to 10.

So I’m going to provide the download file via php file and update the file count to the database. If 10 downloads are reached. I refuse to download.

But I’m guessing it will consume more resources. Is there any other possible way to do it in a Linux server, such as using htaccess or something similar? So when a file has been accessed 10 times, it should be automatically deleted.

EDIT: It’s not a user… This website is free for anyone to use.

Solution

If you don’t want to avoid database queries for this, you can apply a simple technique in the file name to indicate the remaining limit, such as filename-10, filename-9, and so on. But to use this method, you need to update the “part after” -” every download.

This could be one way.

Related Problems and Solutions