One Time Temporary Download Link with Expiration

September 21, 2022 - WK Group Free
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

One-Time Temporary Download Link with Expiration in PHP. A temporary download link is very helpful for offering digital products on the site. It provides a safe way to share the download link of premium items. The client allows the record to be downloaded only once, after the download the link is terminated or cleared.

A one-time download link is perfect for giving a single individual an innovative item (code, music, video, etc.) and terminates the link once the item is downloaded. One-Time Temporary Download Link with Expiration

With Single Utilities Download Link, you don’t need to physically screen the download action keeping in mind the end goal of changing the download link. Rather, the download link will be terminated immediately after the primary download. In this tutorial, we will show you the proper procedure to generate a temporary download link in PHP and implement a temporary download URL utility on a web application using PHP.

One Time Temporary Download Link with Expiration
One-Time Temporary Download Link with Expiration

The example code enables you to create a link of sorts to download a document from the server. This link will enable the client to download it once. Likewise, the link will have an expiration time and it will expire after predetermined expiration date.

For example, you need to offer an eBook on your site. If the eBook is sold on your site for $5, you can use our content to get that client to download a separate eBook just once. The download link will give them a predetermined number of seconds/minutes/hours/days/weeks/years to push their download.

The following procedure will be taken to implement the temporary download link functionality in PHP.

  • Create a download link with a special key.
  • Make a secured directory to store keys.
  • Make a file and write a unique key to it.
  • On download ask for, a token key, and lapse time is approved.
  • Power the program to download the record.

Setups (config.php)

The setup factors are characterized in this document.

  • $files – A variety of the records with the one-of-a-kind ID.
  •  You can indicate the distinctive name of the record downloaded. It secures the first document.
  • You can determine the nearby or remote record way.
  • BASE_URL – Define the URL of the application.
  • DOWNLOAD_PATH – Define the way the document downloads content.
  • TOKEN_DIR – Set the token directory way where the keys will be put away.
  • OAUTH_PASSWORD – Set the verification secret word to produce a download link.
  • EXPIRATION_TIME – Set a period when the document will terminate.


In this document, a link will be shown to explore the download link creation record. The confirmation secret key should be indicated in the inquiry string of the link.

Make Temporary Download Link (generate-link.php)

This document makes a temporary download link and records the links on the page. The inquiry string must have the verification watchword and should be coordinated with the predefined in the config.php document, generally, 404 mistakes are rendered.

  • Get the validation secret word from the question string.
  • Approve the validation secret word.
  • Encode the record ID with base64_encode() in PHP.
  • Produce another interesting key with a timestamp utilizing uniqid() in PHP.
  • Create a download link with the record ID and key.
  • Make a secured directory to store keys.
  • Write the key in a record and place it in the token directory.
  • List all the download links on the page.

Download File by Temporary Link (download-link.php)

This document downloads the record by the temporary download link.

  • Get the document ID and key from the question string of the URL.
  • Get the time from the key and figure out the link termination time.
  • Recover the keys from the tokens record.
  • Circle through the keys to discover a match, when the match is discovered, evacuate it.
  • Put the rest of the keys again into the tokens record.
  • if a match is found and the link isn’t expired

How To Download Source Code

  •  Go To Top On This Post
  • Click On Free Download Button
  • Go to Next Page And Click Source Code Button
  • Go to Next Page & Wait for Some Seconds
  • Your download will begin automatically
  • Submit a paid service request

In Hindi


Are you want to get implementation help, or modify or extend the functionality of this script? Submit a paid service request