你好呀
好的,事情就这样了
我的服务器上有我的 mp3 文件,每个文件都在其自己的文件夹中。
该文件夹中有 mp3 和一个包含以下脚本的 php 文件:
<?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 文件有问题。
尝试这个更完整的例子,取自http://us.php.net/readfile http://us.php.net/readfile
<?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;
}
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)