一键下载文件并拨打感谢页面


File download and Thanks page call in one button press

我在一个网站上有一个下载页面,上面有很多ZIP文件的链接。我想允许用户点击下载按钮下载ZIP文件——此外,当他们点击按钮时,我希望浏览器将用户重定向到感谢页面。

这可能吗?如果有帮助的话,这个网站是基于PHP的!

我读到你不能一按就完成,所以需要调用下载感谢页面,然后从感谢页面提供下载文件功能。。。如果我有很多下载按钮/文件,这怎么可能呢?是否需要将一个变量从下载页面发送到下载感谢页面,以允许感谢页面处理要下载的正确文件???

**********更新**********

好吧,我尝试过实现PHP变量和GET函数,但我并不高兴,代码如下所示,并链接到这里的实际示例http://www.example.biz/clients/example/downloads/-加载感谢页面的调用被忽略,我只收到保存文件下载的提示???

下载页面:

    <a href="http://www.example.biz/clients/example/downloads/thanks.php?file=zip1">zip1</a>
    <a href="http://www.example.biz/clients/example/downloads/thanks.php?file=zip2">zip2</a>
    <a href="http://www.example.biz/clients/example/downloads/thanks.php?file=zip3">zip3</a>

thanks.php页面:

    <?php
    $file = $_GET['file'];
    if($file == "zip1")
    {
    header("Location: http://www.example.biz/clients/example/downloads/zip1.zip");
    }
    else if($file == "zip2")
    {
    header("Location: http://www.example.biz/clients/example/downloads/zip2.zip");
    }
    else if($file == "zip3")
    {
    header("Location: http://www.example.biz/clients/example/downloads/zip3.zip");
    }
    echo "Thankyou for downloading";
    ?>

**********更新2*********

放弃了PHP,因为实际的PHP下载页面永远不会在屏幕上呈现——它提供了正确的下载,但感谢页面永远不会呈现。。。使用JS解决方案如下:

    <script>
    function thanks() {
        setTimeout(function () {
            document.location.pathname = "thanks.html";
        }, 1000);
    }
    </script>
    <a href="zip1.zip" onclick="thanks()">zip1</a>

您可以简单地将$_GET值传递到感谢页面。。。即,当用户单击按钮时,该按钮具有一个窗体或javascript的window.location函数,该函数将用户重定向到感谢页面,您可以很容易地传递$_GET值,如:

http://www.somthing.com/thanks-download-page.php?fileid=1

thanks-download-page.php中,您可以读取$_GET['fileid']值,然后将该值传递给数据库或任何您想要获得文件位置详细信息的东西。。。

这是什么?

下载页面

<a href="thankyou.php?file=zip1">zip1</a>
<a href="thankyou.php?file=zip2">zip2</a>
<a href="thankyou.php?file=zip3">zip3</a>

感谢页面

<?php
$file = $_GET['file'];
if($file == "zip1")
{
   header("Location: http://domain.com/zip1.zip");
}
else if($file == "zip2")
{
   header("Location: http://domain.com/zip1.zip");
}
echo "Thankyou for downloading";
?>

如果您从感谢页面重定向到文件下载链接。当浏览器处理下载链接时,它不会更改html文档视图。

你可以用javascript来实现。