创建一个到实际文件的符号链接,并在符号链接中创建下载链接点。然后,当用户点击DL链接时,他们将从实际文件中下载文件,但是从符号链接命名。创建符号链接需要几毫秒的时间,并且比试图将文件复制到新名称并从那里下载要好。
例如:
<?php
// validation code here
$realFile = "Hidden_Zip_File.zip";
$id = "UserID1234";
if ($_COOKIE['authvalid'] == "true") {
$newFile = sprintf("myzipfile_%s.zip", $id); //creates: myzipfile_UserID1234.zip
system(sprintf('ln -s %s %s', $realFile, $newFile), $retval);
if ($retval != 0) {
die("Error getting download file.");
}
$dlLink = "/downloads/hiddenfiles/".$newFile;
}
// rest of code
?>
<a href="<?php echo $dlLink; ?>Download File</a>
这就是我所做的,因为去爸爸杀死了2分30秒左右后,运行该脚本....这防止问题和隐藏实际的文件。
然后,您可以设置一个cron作业来删除定期符号链接....
这整个过程,然后将文件发送到浏览器并不要紧运行多长时间,因为它的不是脚本。
这个问题的一部分可以通过支持`Range`头来解决,所以浏览器可以暂停和恢复下载。这是一个问题处理:http://stackoverflow.com/questions/157318/resumable-downloads-when-using-php-to-send-the-file – grossvogel 2010-11-08 19:01:15
也请看看[this](http:// stackoverflow.com/a/6527829/1469208)和[this](http://stackoverflow.com/a/21354337/1469208)SO答案。 – trejder 2014-02-21 13:06:43
在这里看到 - https://stackoverflow.com/questions/47827768/how-to-download-large-files-with-php/47827769#47827769 – Aplextor 2017-12-15 07:40:56