我编写了一个脚本来强制从站点下载mp3文件。代码运行得很好,但问题是它不能下载大文件。我尝试了一个9.21mb的文件,它下载正确,但每当我尝试使用代码下载一个25mb的文件,它只是给我一个无法找到服务器页面或网站无法显示该页面。所以我现在知道它在下载大文件时遇到了问题。下面是下载文件的代码片段。
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$dname.".mp3\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($secretfile));
$downloaded=readfile($secretfile); 显示的错误是: HTTP 500内部服务器错误
非常感谢你们抽出时间,各位。
发布于 2009-02-23 18:00:00
试试这个:
// empty output buffer
while (ob_get_level()) {
ob_end_clean();
}
if (ini_get('output_buffering')) {
ini_get('output_buffering', false);
}
// function to encode quoted-string tokens
function rfc2822_quoteString($string) {
return '"'.preg_replace('/[^\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]/', '\\\$0', $string).'"';
}
// HTTP headers
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.rfc2822_quoteString($dname.'.mp3'));
header('Content-Length: '.filesize($secretfile));
// send file
readfile($secretfile);
exit;https://stackoverflow.com/questions/578507
复制相似问题