1

现在我得到了这个代码;

<?php

$file = "pain.png";

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;
}
?>

此代码出现一个下载框。但我想在下载框还在这里时将此页面重定向到“谢谢”页面。我怎样才能做到这一点?

谢谢...

4

2 回答 2

2

您可以使用元刷新 ( http://en.wikipedia.org/wiki/Meta_refresh )完成此操作

你会像这样从你的主页链接到你的下载页面。

索引.html

  <html><head></head><body>
Download my awesome <a href="download.html">file</a>
</body></html>

下载.html

    <html>
        <head>
        <meta http-equiv="refresh" content="0;url=http://example.com/download.php" />
        </head>
        <body>
        Thanks for choosing Foobar!  Your download will begin shortly.
    If you're download does not begin, 
click <a href="http://www.example.com/download.php">here</a>
        </body>
        </html>
于 2010-03-27T13:55:10.027 回答
0

由于下载HTTP 响应,因此您无法从下载响应中进行下载。您可以重定向它们,然后说“谢谢,您的下载将立即进行”等等。这似乎是大多数地方的标准解决方案。

需要明确的是,感谢页面将重定向到下载 URL。

于 2010-03-27T13:54:11.277 回答