CREATE EXPIRE DOWNLOAD LINK IN PHP MYSQL | BEST TUTORIAL

Subscribe

Ever wonder how to create a download link in PHP and then make it expire? Would you like to know how to expire a download link after a set number of times they download it? Do you want to know how to protect your files from people trying to steal your downloads? We are going to answer those questions and more on this tutorial.

Setting Up The Database For Expired Links

Set up your database first. Create a database and then use the following code to set up the table and rows. Let me tell you what each row is going to do. The link row is going to save an encrypted link that you will use for your application. This will appear in the URL address bar. The file is going to be the name of the file you are uploading for a user to download. The counting row is going to keep track of how many times you allow a file to be downloaded. The expire row is going to keep track of the time you set for the link to expire. The tstamp row is going to keep track of the time that you uploaded the file.

 

CREATE TABLE `links` (
`id` int(11) NOT NULL,
`link` char(40) NOT NULL,
`file` text NOT NULL,
`counting` int(11) NOT NULL DEFAULT 11,
`expire` int(11) NOT NULL,
`tstamp` int(10) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;;

 

For Future Projects

Keep in mind this tutorial is showing you how to do something like this. In the future, you can build on this further to create purchases or user activations on a website or app.

File To Create Expired Download Link

Here are the complete files to create expired download links in PHP. Now lets talk about the files so you understand what they do.

CREATE EXPIRE DOWNLOAD LINK IN PHP MYSQL | BEST TUTORIAL was last modified: October 30th, 2021 by Maximus Mccullough

CREATE EXPIRE DOWNLOAD LINK IN PHP MYSQ

Pages: 1 2 Next

8 Comments

  • Boban says:

    Hi
    Very good ! ! !
    How to upload multiple file and create ZIP file ?

  • Jake Roberts says:

    Mine won’t go over 100 mb and I followed to a T

    • Put this in a php tag and put it on your server [php]<?php phpinfo(); ?>[/php] that should tell you the limit for your uploads. If that is the case you will have to increase it on your server.

  • Dragos says:

    Hi!b How to delete a link from the database and how to display in webpage existing links in the database (mysql) ? Thx

    • HI Dragos. On page 2 for the download.php file you will see this
      // delete link so it can't be used again
      mysqli_query($db,"DELETE FROM links WHERE link='$link' AND counting < '1' ");

      This code is responsible for deleting the link in the database. For displaying the link you would query the database. Something like this.

      $result = $db->query("SELECT * FROM links") ;

      while ($row = $result->fetch_assoc()) {

      echo $row[‘link’];

      }

  • Dragos says:

    I can only delete from the server the whole table of links, not each individual. I did some tests and there are links with a higher validity. I would like to be able to see all the submitted links on the index.php page and be able to delete them individually if I need to. If I try to add your script to the index.php page, I get the error:
    ( ! ) Warning: Unknown: Invalid date.timezone value ‘UTC+02.00’, we selected the timezone ‘UTC’ for now. in Unknown on line 0
    ( ! ) Parse error: syntax error, unexpected end of file in D:\wamp64\www\website\downloadlink\index.php on line 91
    downloadlink is the folder with all download from your website

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.