How to create a (custom) number of temporary download links

I create a download link that only works 10 times. So I have 2 options.

  • Uploading a file and updating its number to the database and deleting the file when the number is 10.
  • Or uploading a file and renaming it to filename-1, filename-2 ....... filename-10 .. and finally delete it when it reaches file name-10.

I assume that the second option uses less resources to not invoke the database. Now what is an easy way to find the file name. For instance:

All my file names are unique, for example sadkjsah78876djhgsadj.jpg . So when I update the account, it will look like

sadkjsah78876djhgsadj-1.jpg
(or)
sadkjsah78876djhgsadj-8.jpg

So how to find the file name based on sadkjsah78876djhgsadj in the directory. I think of cyclization. but I don’t think this is the best method when I set the download limit to 100.

+4
source share
1 answer

The best option is to use .htaccessc mod_rewiteto rewrite calls to a specific directory in a PHP file. for example, any calls are /downloads/FILEHASH.jpgrewritten as/download.php?file=FILEHASH

Then it download.phpwill check whether the FILEHASHrow in the database matches and that the dl number was under x, if so, it would increase the dl number, set the response code as 200, content-type up image/jpegand run the image data (either saved in the file system or from the BLOB to DB).

dl x, 404 ( - , ), , . , , .

MVC, .

, , , mime upload , .

+1

Source: https://habr.com/ru/post/1589355/


All Articles