Page 1 of 1
Download File Securely
Posted: Tue Jul 20, 2010 8:19 am
by Number1SuperGuy
I need to create a TXT file for the user, but I don't want to simply store it the server because it's sensitive information, and it seems like someone could just type
www.server.com/filename.TXT and steal this sensitive information.
Is it possible to create a TXT file for a user to download without ever storing it on the server? Any other ideas?
Re: Download File Securely
Posted: Tue Jul 20, 2010 9:25 am
by Apollo
Several options:
1 - generate the data on-the-fly whenever the user requests it
2 - encrypt the data so that downloading is only possible with the right credentials
And regardless of this, make sure you're using SSL (https) otherwise anyone will be able to sniff the data, no matter how well you protect it server-side.
Re: Download File Securely
Posted: Tue Jul 20, 2010 9:58 am
by Number1SuperGuy
Definitely getting SSL

I'm able to generate this data on-the-fly, in fact that's preferred, how can I let the user save this data as a text file without storing it on the server first?
Re: Download File Securely
Posted: Tue Jul 20, 2010 10:43 am
by Apollo
Code: Select all
<?php
$s = "Generate file contents here";
$s .= "\n bla \n bla \n bla...";
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: text/plain; charset=utf-8');
header('Content-Length: '.strlen($s));
header('Content-Disposition: attachment; filename="TopSecret.txt"');
die($s);
?>