gpt4 book ai didi

javascript - 如何根据 php 中的按钮操作传递点击次数

转载 作者:行者123 更新时间:2023-11-30 08:37:52 24 4
gpt4 key购买 nike

我们正在开发网站。我们有按钮。在按钮操作中,我们放置了 PDF 文件下载。工作正常。但我们需要如何计算从我的网站下载我的 PDF 文件。

我们这样试过,但我们没有得到。

<?php
//$Down=$_GET['Down'];
$a="hello";
$i=0;
?>
<script type="text/javascript">
var i=0;
function submitForm()
{
<?php
$i = @file_get_contents('count.txt'); // read the hit count from file
echo $i; // display the hit count
$i++; // increment the hit count by 1
@file_put_contents('count.txt', $i); // store the new hit count
?>
}
</script>
<html>
<head>
</head>

<body>
<input type="button" onclick="submitForm()" value="submit 1" />
</body>
</html>

我们什么都没有。我们是 PHP 的新手,请指导我们。

最佳答案

好吧,您可以下载 PDF 并在表单提交时计数:

<?php
$i=0;
$i = (int) @file_get_contents('count.txt'); // read the hit count from file
if(!empty($_POST)) {
$i++; // increment the hit count by 1
@file_put_contents('count.txt', $i); // store the new hit count
// Download
$file = 'filename.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
}

现在使用 echo $i; 来显示下载数量。

在 html 中,表单应该是:

<form method="post" action="">
<input type="submit" name="download" value="Download">
</form>

关于javascript - 如何根据 php 中的按钮操作传递点击次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29801246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com