也許吧。嘗試還加入了內容長度標題:
header('Content-length: '.filesize($filename));
如果這仍然不起作用,(<?php
前echo
的或空格)之前readfile
檢查任何輸出。還請檢查?>
之後是否沒有空格,或者乾脆省略?>
(如果以後沒有任何內容,則不是必需的)。
由於布魯諾提到,爲了支持流式傳輸,您還需要遵守Range
標頭。這裏是一個簡單的例子,只尊重左邊界:
if (empty($_SERVER["HTTP_RANGE"])) {
//do your current stuff...
}
else { //violes rfc2616, which requires ignoring the header if it's invalid
preg_match("/^bytes=(\d+)-/i",$_SERVER["HTTP_RANGE"], $matches);
$offset = (int) $matches[1];
if ($offset < $filesize && $offset >= 0) {
if (@fseek($fp, $offset, SEEK_SET) != 0)
die("err");
header("HTTP/1.1 206 Partial Content");
header("Content-Range: bytes $offset-".($filesize - 1)."/$filesize");
}
else {
header("HTTP/1.1 416 Requested Range Not Satisfiable");
die();
}
//fread in loop here
}
我猜你的意思是'內容Length',而不是'內容size' – Bruno 2010-07-11 11:00:27
@Bruno你說得對。謝謝! – Artefacto 2010-07-11 11:11:29