| | #1 |
| The Cave Man War Room Member Join Date: 2010
Posts: 334
Thanks: 59
Thanked 96 Times in 79 Posts
|
Hi Guys I want to know if there is someone here knows a script on downloading random files. Example I have a download link and I have different files link like file1 link, file2 link, file3 link etc. if someone click the download link the script will automatically randomly pick a file on different files link and will automatically download. |
| |
| | #2 |
| Advanced Warrior War Room Member Join Date: 2006 Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
|
Easy. Assuming you have 4 files, named file1.zip, file2.zip, file3.zip, file4.zip, and those files are in the same directory as your webpage... <a href="<?php echo 'file' . rand(1,4) . '.zip'; ?>">Click here to download</a> Just change the '4' to the number of files you have, and be sure to give that page a PHP extension. |
| | |
| |
| | #3 |
| The Cave Man War Room Member Join Date: 2010
Posts: 334
Thanks: 59
Thanked 96 Times in 79 Posts
|
Thanks Brandon, how about if the files are hosted in file hosting website and all I have is the links of the files. How can I do that? Example someone pay me in my paypal account and after paying they will receive a random downloaded file. The files are hosting in a file hosting website so how can I do the script? |
| Hooked To Success -Personal development For People Who Wants Success.
| |
| |
| | #4 |
| Advanced Warrior War Room Member Join Date: 2006 Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
|
If the URL's of the files on the file hosting site don't have a consistent naming pattern (most likely the case), then you would have to use conditional statements, like... <?php $random = rand(1, 3); if ($random == "1") { $link = "http://www.FileHostingWebsite.com/file1.html"; } elseif ($random == "2") { $link = "http://www.FileHostingWebsite.com/file2.html"; } elseif ($random == "3") { $link = "http://www.FileHostingWebsite.com/file3.html"; } ?> ^ You can probably figure out which parts of the code you have to change, but if not, just let me know. Put all of that code at the very top of the page, above all other HTML code. Then use the following code wherever you want the link to appear.... <a href="<?php echo $link; ?>">Click here to download</a> |
| | |
| |
| | #5 |
| The Cave Man War Room Member Join Date: 2010
Posts: 334
Thanks: 59
Thanked 96 Times in 79 Posts
|
OK Thanks I will try it out.
|
| Hooked To Success -Personal development For People Who Wants Success.
| |
| |
|
| Bookmarks |
| Tags |
| download, file, random, script |
| |