我使用强制下载脚本来避免在我的网站上播放mp3文件。它在我的电脑上工作,但在我的安卓手机上,下载无法开始!!在我的android平板电脑上,文件扩展名变成了filename.mp3;所以文件必须重命名才能工作!!
这里有什么问题?
<?php
$file=str_replace("'0", null, htmlspecialchars($_GET['file']));
$name = $_GET['name'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$name.";");
readfile($file);
exit;
?>
我只是做了一个小小的改变,它在平板电脑上工作得很好。但是我的安卓手机没有下载。
header("Content-Disposition: attachment;filename = $name");
文件名头看起来不正确。试试这个:
header('Content-Disposition: attachment; filename="'.$name.'"');
看:http://php.net/manual/en/function.header.php
文件名后面有一个分号:
.";");
删除文件名后的;
。基于规范只是一个引号字符串
标题应该像这样出现(注意文件名前的空格和文件名周围的引号)
header("Content-Disposition: attachment; filename='"".$name."'"");
如果你把它改成header ('Content-disposition: attachment;文件名= "。美元的名字。' ' ')它应该工作。
如果你看一下RFC 2616,你会注意到在19.5.1中分号只将配置类型(即"附件")与文件名分开,并且文件名应该是一个引号字符串。