0

这是问题的详细信息:

1)我想创建动态(基于IP)下载链接。所以用户不能用相同的下载链接下载不同IP的文件。

2)在开始实际下载之前,我想使用 php 记录这个下载请求并执行一些检查(验证 http 引荐来源网址)以允许用户下载实际文件。

3)我还希望下载文件是可恢复的,并且可以使用下载管理器下载(具有多个下载实例)。还希望限制每次下载允许的最大实例数。

4) 文件大小可能超过 200 MB。

因此,我正在考虑的解决方案是使用用户 ip 的 md5 哈希创建下载链接。例如 http://yourdomain.com/download.php?ip_hash=hash-of-the-ip&file=file-to-download

这只是一个示例,但我们也可以使用 htaccess 创建一个很好的链接。

接下来我该怎么办?我试着用

header("Content-Type: $ctype");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=\"$fileName\"");
readfile($file);

但是使用这个下载不会对最终用户保持恢复。

使用这种方法发送大文件可以吗?

在做了一些研究之后,我才知道最终用户使用这种方式的 .exe 文件已损坏。

4

1 回答 1

1

在做了更多的研究之后,我找到了我的问题的答案。我只是想我也应该与你们分享。

正如 rambo 所说,我们可以使用 apache 服务器的 mod_xsendfile 模块。如果它被禁用,我们需要启用它。

如果您的 apache 没有此模块,这里是下载模块文件的链接。它适用于几乎所有版本的 apache,并且适用于 x32 和 x64。
https://github.com/nmaier/mod_xsendfile

完成所有自定义验证后,您可以使用以下代码使用此 apache 模块发送文件。

<?php
//We want to force a download box with the filename hello.txt
header('Content-Disposition: attachment;filename=hello.txt');

//File is located at data/hello.txt
header('X-Sendfile: data/hello.txt');
?>

我希望它会帮助你们:)

于 2012-06-28T10:05:02.330 回答