我有一个非常简单的隐藏下载路径脚本的设置是这样的:在readfile中包含源文件名?
在index.html的我有此链接:
<a href="savefile.php">save</a>
在savefile.php我有这段代码:
$file = 'http://www.mysite.com/files/correct_horse_battery_staple.rar';
header("Content-Type: application/force-download");
@readfile($file);
这似乎工作,但不幸的是它下载文件为savefile.php
而不是correct_horse_battery_staple.rar
。
有什么办法可以改变文件名,也可以改变扩展名吗?
尝试['header('Content-Disposition:attachment; filename =“correct_horse_battery_staple.rar'');'](http://us.php.net/manual/en/function.header.php#example- 4365)。如果你的文件名包含非ASCII字符,那么让它在浏览器中显示会更加复杂。 (编辑:另外,使用本地路径而不是基于'http://'的文件。) – DCoder 2013-04-06 14:32:59