Forum Moderators: coopster

Message Too Old, No Replies

File downloadable only once?

         

daperson0

10:46 pm on Feb 16, 2008 (gmt 0)

10+ Year Member



Is it possible to make a file downloadbale only once? I've got an encrypted file storage system working using php, however when a file is requested, the system supposedly decrypts it and allows you to download it. Obviously i don't want this decrypted version hanging around, so i need a way to make the file stop existing after it's been downloaded once, or even better, make the file never get created in the first place!
Any ideas?

FiRe

5:00 pm on Feb 17, 2008 (gmt 0)

10+ Year Member



Something like this..

<?php
$download_id = 5;
$q = mysql_query("SELECT * FROM downloads WHERE id = $download_id");
$r = mysql_fetch_array($q);

if ($r['expired'] == 1) {
echo "This download has expired";
}
else {

mysql_query("UPDATE downloads SET expired = 1 WHERE id = $download_id");

$file = $r['download_file'];

header("Cache-Control: public, must-revalidate");
header("Content-Type: application/octet-stream");
header("Content-Length: " .(string)(filesize($file)) );
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($file);

}
?>

PHP_Chimp

5:09 pm on Feb 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is your file storage system based on? i.e. will the above work, or are you not using a database.

When you say that the system decrypts the file does it then create a temp file for the download, or just allow the real file to be downloaded?

Is this decryption done in response to a password? Or is it just dont for the first person that tries to access the file?

daperson0

6:05 pm on Feb 17, 2008 (gmt 0)

10+ Year Member



The decryption is done in response to a password, but i am unsable to use a database - my server doesn't allow it (grr), so any "database" is actually going to be a pile of text files.
However, i think FiRe's code will probably do it, with a few alterations. Thanks guys, i'll let you know if i have further trouble

henry0

8:09 pm on Feb 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could still use this

FLAT FILE
[webmasterworld.com]