在PHP中可靠地下载大文件 [英] Downloading large files reliably in PHP
问题描述
我在服务器上有一个php脚本来发送文件给收件人:他们得到一个唯一的链接,然后他们可以下载大文件。有时传输有问题,文件已损坏或从不完成。我想知道是否有更好的方式发送大文件
I have a php script on a server to send files to recipents: they get a unique link and then they can download large files. Sometimes there is a problem with the transfer and the file is corrupted or never finishes. I am wondering if there is a better way to send large files
代码:
$f = fopen(DOWNLOAD_DIR.$database[$_REQUEST['fid']]['filePath'], 'r');
while(!feof($f)){
print fgets($f, 1024);
}
fclose($f);
我已经看到了诸如
http_send_file
http_send_data
但我不知道他们会工作。
But I am not sure if they will work.
解决这个问题的最好方法是什么?
What is the best way to solve this problem?
注意
erwing
Regards
erwing
推荐答案
如果您正在发送真正大文件,并担心这将产生的影响,您可以使用x- sendfile头。
If you are sending truly large files and worried about the impact this will have, you could use the x-sendfile header.
从SOQ 使用-xsendfile-with-apache-php ,如何 blog.adaniels.nl:how-i-php-x-sendfile /
这篇关于在PHP中可靠地下载大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!