使用下面的代碼,小文件服務正常,然而很大(見800MB及以上)導致空文件!服務文件(800MB)產生一個空文件
我需要用Apache來做些什麼來解決這個問題嗎?
<?php
class Model_Download {
function __construct($path, $file_name) {
$this->full_path = $path.$file_name;
}
public function execute() {
if ($fd = fopen ($this->full_path, "r")) {
$fsize = filesize($this->full_path);
$path_parts = pathinfo($this->full_path);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
break;
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
}
}
編輯:如果我使用
fpassthru($fd); exit;
相反,我得到下面寫了一個文件中:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 786032641 bytes) in /Users/aaron/Sites/com/library/Model/Download.php on line <i>44
中有什麼一旦他們被下載的文件?嘗試用文本編輯器打開一個。 –
它似乎在傳輸該數據嗎?用whireshark嗅探進一步診斷。 – Caissy
它導致一個空文件,在文本編輯器中打開它顯示其寫入一個空文件。 我會馬上看看whireshark。 – azz0r