[Help] Random File Download Script

by JagSEO
4 replies
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.
#download #file #random #script
  • Profile picture of the author Brandon Tanner
    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.
    Signature

    {{ DiscussionBoard.errors[7962452].message }}
    • Profile picture of the author JagSEO
      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?
      Signature
      Hooked To Success -Personal development For People Who Wants Success.
      {{ DiscussionBoard.errors[7962510].message }}
      • Profile picture of the author Brandon Tanner
        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>
        Signature

        {{ DiscussionBoard.errors[7962591].message }}
        • Profile picture of the author JagSEO
          OK Thanks I will try it out.
          Signature
          Hooked To Success -Personal development For People Who Wants Success.
          {{ DiscussionBoard.errors[7962610].message }}

Trending Topics