作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个下载链接<a href="http://website/filename.pdf">Download</a>
我希望每次当有人点击“下载”时,我都可以将其插入数据库total_downloads+1。为了插入数据库,我通常使用
<form method="POST">
<input type="submit" name="download" value="Download">
</form>
然后
if (isset($_POST['download'])) {...}
但我不知道如何在点击表单中的下载按钮后触发下载。
最佳答案
快速简便的方法是:
header('Location: http://website/filename.pdf');
要对参数进行更多控制,您可以使用以下代码:
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="somename.pdf');
header('Content-Length: '.filesize($filepath) );
readfile($filepath);
关于php - 单击<a> href链接后如何插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16262414/
我是一名优秀的程序员,十分优秀!