• Increase font size
  • Default font size
  • Decrease font size

dynamic download link

Once, I had to face problem, how to generate download link dynamicly. I did not want everybody could download my files by copy pasting link into browser. Here is the solution I have created:

First we need a regular download link. This link is directed to the php script which handles whole process of downloading. Two variables are send to the php script by "GET".

<?php
//uses hash of date to ensure security
$password = "pass";
$strToHash = date('m.d.y').$password;
$hash = hash('md5', $strToHash);
echo "<a href='dl.php?filename=icon.ico&id={$hash}'>working DOWNLOAD</a><br><br>";
echo "<a href='dl.php?filename=icon.ico&id=1'>not working DOWNLOAD</a>";
?>

  1. filename which we want to download
  2. id which is our MD5 hash generated based on the date and a password.
Everythig looks like this:

As you can see, hypertext runs dl.php script. This script has two tasks:

  1. control if it was run by our link. It is done by the hash control
  2. allow us to download the requested file (defined by filename variable)
Here is the code:
<?php
$download_path = "C:\\";    //directory where downloadable files are stored
$password = "pass";         //password
$filename = $_GET['filename'];
$hash1 = $_GET['id'];
$strToHash = date('m.d.y').$password;
$hash2 = hash('md5', $strToHash);
if(strcmp($hash1, $hash2) != 0){
die("Please try again later.");
}
// Detect missing filename
if(!$filename) die("I'm sorry, you must specify a file name to download.");
// Make sure we can't download files above the current directory location.
if(eregi("\.\.", $filename)) die("I'm sorry, you may not download that file.");
$file = str_replace("..", "", $filename);
// Make sure we can't download .ht control files.
if(eregi("\.ht.+", $filename)) die("I'm sorry, you may not download that file.");
// Combine the download path and the filename to create the full path to the file.
$file = "$download_path$file";
// Test to ensure that the file exists.
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
// Extract the type of file which will be sent to the browser as a header
$type = filetype($file);
// Send file headers
header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
readfile($file);
?>

Source code, you may download here.

 

 

Comments  

 
0 #345 live22 download 2019-02-19 22:28
Thanks to my father who stated to me regarding this
website, this blog is genuinely amazing.
Quote
 
 
0 #344 live casino music 2019-02-19 22:18
He's a non-roster invitee, making them just about as much a longshot as 40-man roster members Cofield and Jones.
Evident than when you Quentin's second five RBI game of the year.
Grip on a securities and exchange commission's.
Quote
 
 
0 #343 joker123 download 2019-02-19 07:42
At this time it looks like Expression Engine is the preferred blogging platform out
there right now. (from what I've read) Is that what you are using on your blog?
Quote
 
 
0 #342 live22 download 2019-02-19 03:13
If you see anything thats close from you wanted or better, check its page rank.

When your website has high ranking on those search engines it gets more traffic.
Quote
 
 
0 #341 live22 casino 2019-02-19 01:18
There are numerous ways to generate income
blogging. So a website writer who knows SEO is vital.
Wine beverage you don't say anything derogatory can lead to legal conditions.
Quote
 
 
0 #340 live22 casino 2019-02-19 01:17
There are numerous ways to generate income
blogging. So a website writer who knows SEO is vital.
Wine beverage you don't say anything derogatory can lead to legal conditions.
Quote
 
 
0 #339 play8oy for ipad 2019-02-18 19:19
If you're keen on blogging, essential make sure you might well have installed the
I love social bookmarking plugin. But what when you find
yourself just starting? There are three major search engines namely Google,
Yahoo and MSN.
Quote
 
 
0 #338 scr888 ios 2019-02-17 08:50
Helpful information. Fortunate me I discovered your site by accident, and I'm
shocked why this twist of fate didn't took place in advance!
I bookmarked it.
Quote
 
 
0 #337 918kiss bet 2019-02-15 23:32
Poker tables can be folded up for storage and it can be converted anytime to play.
This is based on basic poker rules, but the big difference is here it is man versus machine.
Quote
 
 
0 #336 n33 2019-02-15 07:01
Pleasantly surprised all in the time I spend when you hit
it involves content creation. Collect pictures of the little one dressed being a nurse,
a chef or even perhaps a teacher.
Quote
 
 
0 #335 mega casino slots 2019-02-14 18:02
Plus reviews of individuals sites. reviews
of stuff. and other good content. After all, that's less that doctor needs
to pump . Try it yourself; create a subject
in which you're interested.
Quote
 
 
0 #334 playboy casino 2019-02-14 15:58
This list could be about certain mistakes, tips, tactics, myths, and thus.
Content is beneficial to an industry. Just
when you paid recycle online doesn't mean it's meaningful.
Quote
 
 
0 #333 download 2019-02-12 22:26
Undeniably consider that that you stated. Your favorite reason appeared to be on the net the easiest factor to
take into accout of. I say to you, I certainly get annoyed even as people
think about issues that they just do not understand about.
You managed to hit the nail upon the top and also outlined out the whole thing without having side-effects ,
other people could take a signal. Will probably be
back to get more. Thank you

Feel free to surf to my blog - download: https://gitlab.com/snippets/1816534
Quote
 
 
0 #332 sky777 download 2019-02-12 20:38
Let me give you some information regarding how this process changes your profits in a big way.
Is it possible to guess what probably happened? There are millions of
hungry article readers online.
Quote
 
 
0 #331 918 kiss 2019-02-12 13:26
Use browser extensions as quickly as possible a make sure the pr
of websites on a tight schedule. It may seem like there are lots of new articles directories popping up every day.
Quote
 
 
0 #330 newtown ntc33 2019-02-12 01:14
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! By the way,
how can we communicate?
Quote
 
 
0 #329 mega888 casino 2019-02-11 23:40
A lot of hosting accounts possess a feature within c-panel the
easy 3 clicks blog setup. I'm a 'scanner' and video just
won't i want to do that most. Determine what works, and copy
them.
Quote
 
 
0 #328 joker123 casino 2019-02-11 14:11
Good day I am so excited I found your web site, I really found
you by accident, while I was searching on Google for something else, Nonetheless I am here
now and would just like to say thank you for a tremendous
post and a all round enjoyable blog (I also love the theme/design), I
don’t have time to look over it all at the moment but I
have bookmarked it and also added in your RSS feeds, so when I have time
I will be back to read a great deal more, Please do keep up the superb
b.
Quote
 
 
0 #327 ublkks.com 2019-02-11 11:32
To shorten the hunting process when you need to compare automobile insurance quickly, you'll
be able to head to one of several websites that will narrow your search.
Liability Insurance and Workman's Compensation insurance
are two required varieties of insurance that equine companies
must have if they have W2 employees and when they're doing any kind business with
all the public. Part b; ublkks.com: https://ublkks.com/elgg2/profile/Candice001, covers doctors' services, hospital outpatient care, and
also some forms of home health care.
Quote
 
 
0 #326 Dale 2019-02-10 20:14
To shorten the hunting process when you need that compares automobile insurance quickly, you can head to one of the websites which will narrow your search.
If you pay all of your premium fully, you are able to ask for the discount from the insurer.

Assuming the identical parameters as before it would make a income of $93,600.


Check out my page: b (Dale: http://veblencorp.com/__media__/js/netsoltrademark.php?d=orken-audit.kz)
Quote
 
 
0 #325 Casey 2019-02-09 09:50
Hey There. I discovered your blog the usage
of msn. That is a very smartly written article. I will make sure
to bookmark it and return to learn extra of
your helpful information. Thanks for the
post. I will definitely return.
Quote
 
 
0 #324 lpe88 download 2019-02-09 08:05
Marketing site is not every that hard to do. Have a subscriber channel that is appropriately tagged and stay busy.
We'll just go through the free examples for immediately.
Quote
 
 
0 #323 lpe88 download 2019-02-09 08:05
Marketing site is not every that hard to do. Have a subscriber channel that is appropriately tagged and stay busy.
We'll just go through the free examples for immediately.
Quote
 

Add comment

No bad words.


Security code
Refresh


New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2048 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2913 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4054 Hits
gpsim tutorial Machine Learning and Robotics
Read More 10121 Hits

Most read content

A* search algorithm Machine Learning and Robotics
Read More 17342 Hits
gpsim tutorial Machine Learning and Robotics
Read More 10121 Hits
PID regulator Machine Learning and Robotics
Read More 10067 Hits

New articles

Differential Equations - Simple spring model Machine Learning and Robotics
Read More 2048 Hits
Kalman Filter implementation Machine Learning and Robotics
Read More 2913 Hits
Inverse kinematics Machine Learning and Robotics
Read More 4054 Hits
gpsim tutorial Machine Learning and Robotics
Read More 10121 Hits
Design by i-cons.ch / etosha-namibia.ch