3

是否可以使用 nginx 或 apache(后端的 php,但 nginx 传递文件)仅计算完整的文件下载(当用户单击接受时保存对话框出现时)?

4

1 回答 1

2

纯 PHP 解决方案可能如下所示(简化):

<?php

$file = $_GET['file'];
check_if_file_is_ok_for_download($file);

header('Content-Type: ...');
header('Content-Length: ...');
header('Content-Dispostion: ...'); 
// more headers if necesarry ...

// output the file
readfile($file);

// count the finished download
database_add_finished_download($file);

然后使用下载链接,如:

http://yourserver.com/download.php?file=...

可以将 url 重写为:

http://yourserver.com/download/...
于 2013-07-12T11:08:22.633 回答