【发布时间】:2010-09-30 15:27:58
【问题描述】:
我有一个 PHP 脚本,它推送标题以允许文件下载。该脚本在通过超链接或通过使用链接的浏览器调用时可以正常工作。看起来是这样的:
<a href="download.php?file=test.mp3&properFilename=Testing File">Download</a>
我希望这是一个按钮(sbumit),所以我这样做了:
<form action="download.php?file=test.mp3&properFilename=Testing File" method="get">
<input type="submit" value="Download Audio" name="download"/>
</form>
但是,这不起作用。当我点击它时。它会启动下载对话框,但文件名是空的。它将文件名显示为“.mp3”(不带引号)!通过超链接的相同链接显示了确切的文件名“测试文件”。为什么是这样??这里是涉及到的 PHP sn-p:
$filename = '../'.$_GET['file'];
$properFilename = $_GET['properFilename'].'.mp3';
header("Content-Disposition: attachment; filename=\"".basename($properFilename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
感谢您的帮助。这让我日日夜夜发疯!!!
【问题讨论】:
标签: php forms http-headers hyperlink download