Author Topic: Expiration date for download links possible?  (Read 4242 times)

0 Members and 1 Guest are viewing this topic.

Offline JGraceffo

  • Occasional poster
  • *
  • Posts: 11
    • View Profile
Expiration date for download links possible?
« on: January 13, 2014, 03:58:45 PM »
Hello again raybob! I was wondering if it would be possible to modify or add some lines of code to have the download links expire  after a few days. I see a lot of places doing this now, and it seems like a good idea for security reasons (who needs someone going back and downloading files you sent them a year ago, and eating your bandwidth).  Thanks in advance for any help!

Offline raybob

  • Moderator
  • Tireless poster
  • *****
  • Posts: 453
    • View Profile
    • FileSplat.com
Re: Expiration date for download links possible?
« Reply #1 on: January 13, 2014, 05:45:54 PM »
Sorry, there's no way to do that.  URLs are hard links to files in the VFS.  You could just manually rename files you don't want downloaded anymore or reset their shared ID.

Offline JGraceffo

  • Occasional poster
  • *
  • Posts: 11
    • View Profile
Re: Expiration date for download links possible?
« Reply #2 on: January 13, 2014, 08:39:48 PM »
I figured that would be the answer and I could change the shared ID or rename them manually, I was just hoping for one less thing for my thinly stretched brain to remember to do.

Thanks again for the quick response!

Offline bmartino1

  • Tireless poster
  • ****
  • Posts: 880
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
Re: Expiration date for download links possible?
« Reply #3 on: April 12, 2014, 06:45:03 PM »
it is possible, but hard to do, in the end you have a url that is hard coded, a link that is then linked to a time web code.
it advanced code, and is possible, either by program or html/php

http://www.whatwg.org/specs/web-apps/current-work/
http://www.webvamp.co.uk/blog/coding/creating-one-time-download-links/

you will have to have sql with hfs and or link to index page with php...

---------------
SQL

CREATE TABLE downloads (
   downloadkey varchar(32) NOT NULL unique,
   file varchar(255) NOT NULL default '',
   downloads int UNSIGNED NOT NULL default '0',
   expires int UNSIGNED NOT NULL default '0'
);
PHP Code

//The directory where the download files are kept - keep outside of the web document root
$strDownloadFolder = "/downloads/";

//If you can download a file more than once
$boolAllowMultipleDownload = 0;

//connect to the DB
$resDB = mysql_connect("localhost", "username", "thisismypassword");
mysql_select_db("database", $resDB);

if(!empty($_GET['key'])){
   //check the DB for the key
   $resCheck = mysql_query("SELECT * FROM downloads WHERE downloadkey = '".mysql_real_escape_string($_GET['key'])."' LIMIT 1");
   $arrCheck = mysql_fetch_assoc($resCheck);
   if(!empty($arrCheck['file'])){
      //check that the download time hasnt expired
      if($arrCheck['expires']>=time()){
         if(!$arrCheck['downloads'] OR $boolAllowMultipleDownload){
            //everything is hunky dory - check the file exists and then let the user download it
            $strDownload = $strDownloadFolder.$arrCheck['file'];

            if(file_exists($strDownload)){

               //get the file content
               $strFile = file_get_contents($strDownload);

               //set the headers to force a download
               header("Content-type: application/force-download");
               header("Content-Disposition: attachment; filename=\"".str_replace(" ", "_", $arrCheck['file'])."\"");

               //echo the file to the user
               echo $strFile;

               //update the DB to say this file has been downloaded
               mysql_query("UPDATE downloads SET downloads = downloads + 1 WHERE downloadkey = '".mysql_real_escape_string($_GET['key'])."' LIMIT 1");

               exit;

            }else{
               echo "We couldn't find the file to download.";
            }
         }else{
            //this file has already been downloaded and multiple downloads are not allowed
            echo "This file has already been downloaded.";
         }
      }else{
         //this download has passed its expiry date
         echo "This download has expired.";
      }
   }else{
      //the download key given didnt match anything in the DB
      echo "No file was found to download.";
   }
}else{
   //No download key wa provided to this script
   echo "No download key was provided. Please return to the previous page and try again.";
}
------------------------
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 586
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Expiration date for download links possible?
« Reply #4 on: April 13, 2014, 02:08:21 AM »
I figured that would be the answer and I could change the shared ID or rename them manually, I was just hoping for one less thing for my thinly stretched brain to remember to do.
...but what happens if someone is still downloading the file, and you change the "Shared ID"?... Will be able to finish the download?
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline bmartino1

  • Tireless poster
  • ****
  • Posts: 880
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
Re: Expiration date for download links possible?
« Reply #5 on: April 14, 2014, 02:42:26 AM »
download times based on a test download with html nite of experiation and 2x time for download...
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1

Offline raybob

  • Moderator
  • Tireless poster
  • *****
  • Posts: 453
    • View Profile
    • FileSplat.com
Re: Expiration date for download links possible?
« Reply #6 on: April 28, 2014, 05:59:05 PM »
...but what happens if someone is still downloading the file, and you change the "Shared ID"?... Will be able to finish the download?

I think so... try it.