0

我对如何允许在付款后下载 file.zip 感到困惑。如果我将他们重定向到文件放置在服务器中的下载页面,他们可以轻松地再次下载文件,或者他们可以将该链接传递给任何人。

请有任何建议!

4

3 回答 3

1

就像@SmokeyPHP 提到的那样,只需通过 PHP 输出文件,而不是直接链接到它。

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>

http://php.net/manual/en/function.readfile.php

这样您就可以完全控制谁下载了什么。当然,根据文件大小,您可能希望将文件分割成更小的块。您不想每 5 秒在服务器内存中缓冲 40 MB 文件。对于更大的文件,您可以使用以下内容:

<?php
$file = fopen("file.dat", "r");
while (!feof($file)) {
    echo fgets($file);
}
fclose($file);

?>
于 2013-07-18T11:52:32.817 回答
1
  1. 将 .zip文件放在网络服务器 之外
  2. 使用某些规则保护 .zip URL [例如登录并购买资源];
  3. 将 .zip URL 与读取实际二进制文件并将其转发给用户的操作相关联 [此处有大量示例]。
于 2013-07-18T11:52:56.193 回答
1

不要使用文件的直接链接 - 使用 PHP 文件将文件作为下载提供,但前提是找到某个会话 var(在确认付款过程中创建)

于 2013-07-18T11:49:50.177 回答