93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Single use download script
2 |
3 | ## Demo
4 | [http://cloud.joshpangell.com/singleuse](http://cloud.joshpangell.com/singleuse)
5 |
6 | ## Brief
7 |
8 | This script was written to be a very easy way for non-programmers to be able to create a secure way to share a single file. It is ideal for bands looking to give a single song to a single person, and invalidating the link once the song has been downloaded. However, it will work for any type of file.
9 |
10 | ## Description
11 |
12 | This script allows you to generate a unique link to download a file. This file will only be allowed to download one time. This link will also have also have an expiration date set on it.
13 |
14 | For instance, if you wanted to sell a song for your band. You sold the song on your website for $1, you could use this script to allow that person to download your song only one time. It would only give them a limited number of hours/days/weeks/years to claim their download.
15 |
16 | You can also mask the name of the file being downloaded, for further protection. For example, if your song was called "greatsong.zip", you could set the download link as "Band_Awesome-Awesome_Song.zip" (it is not a good idea to leave spaces in URL titles)
17 |
18 | ## Update
19 |
20 | On Feb 28, 2018 a feature was added to allow remote files to be downloaded, in addition to local files
21 |
22 | On July 11, 2016 a multi-file feature branch was merged with the single file. It is now possible to download multiple files at once.
23 |
24 | ## Usage
25 |
26 | All files must be uploaded to a directory on your server.
27 | This directory's permissions MUST be `chmod 755`
28 | (Also known as)
29 | `User: read/write/execute`
30 | `Group: read/execute`
31 | `World: read/execute`
32 |
33 | The directory called `secret` must also have the same permissions set as the parent directory.
34 |
35 | You will need to modify the `variables.php` file and set your file specific info.
36 |
37 | // Arrays of content type, suggested names and protected names
38 | $PROTECTED_DOWNLOADS = array(
39 | array(
40 | 'content_type' => 'application/zip',
41 | 'suggested_name' => 'computing.zip',
42 | 'protected_path' => 'secret/file1.zip'
43 | ),
44 | array(
45 | 'content_type' => 'application/zip',
46 | 'suggested_name' => 'star.zip',
47 | 'protected_path' => 'secret/file2.zip'
48 | )
49 | );
50 |
51 | // The path to the download.php file (probably same dir as this file)
52 | define('DOWNLOAD_PATH','/singleuse/download.php');
53 |
54 | // The admin password to generate a new download link
55 | define('ADMIN_PASSWORD','1234');
56 |
57 | // The expiration date of the link (examples: +1 year, +5 days, +13 hours)
58 | define('EXPIRATION_DATE', '+1 month');
59 |
60 | Once this is in place, you are ready to generate a new download key. To do this, you will need to use the password you set in the variables file. In the example above, that is `1234`
61 |
62 | Navigate to `example.com/singleuse/generate.php?1234` (Notice the `?1234` a the end — that is your password)
63 |
64 | Copy the link that is generated and send it off. Voila! Done.
--------------------------------------------------------------------------------
/generate.php:
--------------------------------------------------------------------------------
1 | $download) {
30 | // Create a new key
31 | $new = uniqid('key',TRUE);
32 |
33 | // get download link and file size
34 | $download_link = "http://" . $_SERVER['HTTP_HOST'] . DOWNLOAD_PATH . "?key=" . $new . "&i=" . $key;
35 | $filesize = (isset($download['file_size'])) ? $download['file_size'] : human_filesize(filesize($download['protected_path']), 2);
36 |
37 | // Add to the download list
38 | $download_list[] = array(
39 | 'download_link' => $download_link,
40 | 'filesize' => $filesize
41 | );
42 |
43 | /*
44 | * Create a protected directory to store keys in
45 | */
46 | if(!is_dir('keys')) {
47 | mkdir('keys');
48 | $file = fopen('keys/.htaccess','w');
49 | fwrite($file,"Order allow,deny\nDeny from all");
50 | fclose($file);
51 | }
52 |
53 | /*
54 | * Write the key key to the keys list
55 | */
56 | $file = fopen('keys/keys','a');
57 | fwrite($file,"{$new}\n");
58 | fclose($file);
59 | }
60 | }
61 |
62 | ?>
63 |
64 |
65 |
66 | Download created
67 |
68 |
69 |
70 |
71 |
76 |
77 |
78 |
This script was written to be a very easy way for non-programmers to be able to create a secure way to share a single file. It is ideal for
52 | bands looking to give a single song to a single person, and invalidating the link once the song has been downloaded. However,
53 | it will work for any type of file.
54 |
55 |
Description
56 |
This script allows you to generate a unique link to download a file. This file will only be allowed to be downloaded one time.
57 | This link will also have also have an expiration date set on it.
58 |
59 |
For instance, if you wanted to sell a song for your band. You sold the song on your website for $1, you could use this script
60 | to allow that person to download your song only one time. It would only give them a limited number of hours/days/weeks/years
61 | to claim their download.
62 |
63 |
You can also mask the name of the file being downloaded, for further protection. For example, if your song was called
64 | "greatsong.zip", you could set the download link as "Band_Awesome-Awesome_Song.zip" (it is not a good idea to leave spaces in URL titles)
65 |
Update
66 |
On July 11, 2016 a multi-file feature branch was merged with the single file. It is now possible to download multiple files at once.