我在服务器上有一个php脚本来发送文件给食客:他们得到一个唯一的链接,然后他们可以下载大文件。有时传输出现问题,文件已损坏或永远不会完成。我想知道是否有更好的方式发送大文件
代码:
$f = fopen(DOWNLOAD_DIR.$database[$_REQUEST['fid']]['filePath'], 'r');
while(!feof($f)){
print fgets($f, 1024);
}
fclose($f);我见过像这样的函数
http_send_file
http_send_data但我不确定它们是否会奏效。
解决这个问题的最佳方法是什么?
问候
erwing
发布于 2009-02-28 00:25:19
当我在过去这样做的时候,我使用了这个:
set_time_limit(0); //Set the execution time to infinite.
header('Content-Type: application/exe'); //This was for a LARGE exe (680MB) so the content type was application/exe
readfile($fileName); //readfile will stream the file.这3行代码将完成下载的所有工作,readfile()将流式传输指定给客户端的整个文件,并确保设置无限时间限制,否则您可能会在文件完成流式传输之前耗尽时间。
https://stackoverflow.com/questions/597159
复制相似问题