|
Posted by Steve on 03/13/07 14:44
"kick ass" <pub_lander@yahoo.com> wrote in message
news:et613g$a67$1@news1.carnet.hr...
| Hi,
| this is my question:
| I have a link to some file (file.zip) on my page.
| I would like that this file is automaticaly deleted from server after user
| downloads it.
|
| So, user clicks right mouse button, chooses "Save target as..." and than
| saves it.
| How to make script that deletes file from server after it's been
| downloaded??
|
| I'm out of ideas..
| Thanks for any help (the simple, the better :)
please explain what you are trying to accomplish. this is bad news
architecturally! your user is going to be pissed when he gets corrupt or
partial data caused by transport anomolies (i.e. network). your server would
have deleted the file and your user has no recourse...it's gone.
what i'd recommend (without knowing any of your intentions), is to set an
expiration on a file. when the user 'gets' the file, php sets an expiration
date on the file on the server. you either have a windows scheduled task or
a cron execute a php script that kills off all expired files...run it as
frequently as you see fit.
that would allow for shitty downloads to be attempted again and doesn't
place any responsibility on the end-user to manage (i.e. delete from your
server) the file(s) they are working with.
i use the following code to serve up downloadable files. you'd point your
href's to this script, giving the name of the file to retreive as an arg to
the query string. you would only have to place a line or two of code in this
script to update a db (or similar mechanism) with the file name/path and its
expiration. hth:
<?
require_once 'site.cfg.php';
$fileData = '';
$fileName = $_REQUEST['fileName'];
$filePath = $site->uploadBaseDirectory;
if ($fileName != ''){ $fileData = @file_get_contents($filePath .
$fileName); }
header('pragma: public' );
header('expires: 0' );
header('cache-control: private', false );
header('cache-control: must-revalidate, post-check=0, pre-check=0' );
header('content-disposition: attachment; filename="' . $fileName . '"' );
header('content-size: ' . count($fileData) );
header('content-transfer-encoding: binary' );
header('content-type: application/octet-stream' );
echo $fileData;
?>
Navigation:
[Reply to this message]
|