所以我认为我只能使用.hhtaccess 设置什么信头
所以我用php解决了这个问题
I initially copied a download php script found here:
How to rewrite and set headers at the same time in Apache
但我的文件大小太大了 所以这不起作用
」 http://teddy.fr/blog/how-serve- big-files- through-php http://teddy.fr/blog/how-serve- big-files- through-php
因此,我的完全解决方案如下:
首先发送下载脚本的请求 :
RewriteRule ^download/([^/.]+)/?$ downloads/download.php?download=$1 [L]
然后获得完整的文件名, 设置信头, 并按块为它服务 :
<?php
if ($_GET[ download ]){
$file = $_SERVER[ DOCUMENT_ROOT ]. media/downloads/ . $_GET[ download ] . .zip ;
}
define( CHUNK_SIZE , 1024*1024); // Size (in bytes) of tiles chunk
// Read a file and display its content chunk by chunk
function readfile_chunked($filename, $retbytes = TRUE) {
$buffer = ;
$cnt =0;
// $handle = fopen($filename, rb );
$handle = fopen($filename, rb );
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, CHUNK_SIZE);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status) {
return $cnt; // return num. bytes delivered like readfile() does.
}
return $status;
}
$save_as_name = basename($file);
header( Cache-Control: must-revalidate, post-check=0, pre-check=0 );
header( Pragma: no-cache );
header("Content-Type: application/zip");
header("Content-Disposition: disposition-type=attachment; filename="$save_as_name"");
readfile_chunked($file);
?>