<?php
// We'll be outputting a PDF
header('Content-type: audio/mp3');
// It will be called file.mp3
header('Content-Disposition: attachment; filename="mysong.mp3"');
// The PDF source is in original.mp3
readfile("mysong.mp3");
?>
问题是,当我点击进入那个php页面时,标题是为了让它自动下载mp3文件,当它下载时它会下载一个300KB的文件,但是当我转到mp3的实际链接时文件它在浏览器中完美地播放它所以我猜测给出标题的php文件有问题。
答案 0 :(得分:6)
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
答案 1 :(得分:0)