views:

37

answers:

1

Hi I am sorry if this question has been asked before but I am looking for some sort of download authentication. In other words if I am going to give the user a link to a file, I want to make sure only that person will get it, and get it only once! Is there a simple solution without setting up the database? Even better if it's possible to have an ecrypted web link that will let you download a file from my FTP server just once, after that the link becomes invalid.

Thanks.

+2  A: 

You can use simple php script. This script returing inputet in GET file on the brower. After his excecution you can rename this file to random string. this only first person download this file. Your link get somethis like this. www.domain.tld/dir/script.php?file=./usr/123.tar.gz. You can filename encrypt in base64 too, in this option your link is www.domain.tld/dir/script.php?file=Li91c3IvMTIzLnRhci5neg==

Script without base64:

<?php
$file = $_GET['file'];

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    rename($file, "secret_new_filename");
    exit;
}
else
{
    echo 'File don\'t exist';
}
?>

And with base64:

<?php
$file = base64_decode($_GET['file']);

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    rename($file, "secret_new_filename");
    exit;
}
else
{
    echo 'File don\'t exist';
}
?>
Svisstack
That's a very good idea Svisstack. Unfortunately I don't know PHP all that well. Is there a script around that does just that?
Silence of 2012
I write this script, give me a moment.
Svisstack
Wow thanks a lot! /respect!
Silence of 2012
You must add in filename on a start ./
Svisstack