復制代碼 代碼如下:
if (file_exists($file_path)) { //如果文件存在
$handle = fopen($file_path, "r");
while (!feof($handle)) {
$content = fgets($handle, 4096); //讀取一行
echo $content; //輸出到緩沖區,即php://stdout。達到緩沖區設置值后由tcp傳給瀏覽器進行輸出 一般到512字節就會通過網絡輸出給瀏覽器
}
fclose($handle);
}
復制代碼 代碼如下:
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
Header("Content-type: application/octet-stream"); //響應內容類型
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($filename). ' bytes');
Header('Content-Disposition: attachment; filename='.$filename); //HTTP響應頭
新聞熱點
疑難解答