【发布时间】:2013-04-14 23:55:02
【问题描述】:
特别是,我有一个带有POST 的一些参数的表单提交给自己,但我想在提交表单时保留GET 参数。
例如,如果原始 URL 是 http://mydomain.com/download.php?fname=foobar.bin,我希望它是我创建 POST 时的 URL。但是 URL 的 foobar.bin 部分可能会改变。
这是一个最小的工作示例
<?php
$pass = $_POST['pass'];
$filename = $_GET['p'];
$file = "../../cgi-secret/$filename";
if($pass == "foobar")
{
header('Content-type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
// The PDF source is in original.pdf
readfile($file);
}
if(isset($_POST))
{?>
<form method="POST" action="download.php?p=$file">
Password <input type="password" name="pass"></input>
<input type="submit" name="submit" value="Get File" ></input>
</form>
<?}
?>
在这一行,我想发布到当前 URL,无论发生什么
<form method="POST" action="download.php?p=$filename">
为了提供一些上下文,我正在尝试修改我的问题的答案
How can I password protect a binary file download? 这样我就可以将文件名作为GET 参数传递。
【问题讨论】: