1

文件下载正常 - 除了较大的文件下载 - 大文件下载太快并且在打开时损坏 - 我收到错误消息(对于 zip 文件):无法打开文件:它似乎不是一个有效的存档。文件上传正常,在文件夹中

这是我用来强制下载标头的 php 代码

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, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
4

3 回答 3

0

Found the solution

It was a Maximum memory allocation problem - it had a php default setting of 236M

I upped this and its working

appreciate all the help

Regards

Jeff

于 2012-07-25T10:12:35.850 回答
0

首先尝试直接访问该文件(指向 zip 文件的直接 URL)。

如果它也给出错误或损坏,请使用流编写器之类的东西一次写入数据块。

(假设服务器端文件没有损坏)

或者使用这样的东西

http://php.net/manual/en/httpresponse.send.php

于 2012-07-25T09:35:08.307 回答
0

即使通过增加内存分配,下载仍然非常不可靠。我设法通过使用以下方法使其稳定。感谢大家的投入。

header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.

$fp = fopen($file, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
} 
fclose($fp); 
于 2012-07-26T14:14:04.203 回答