使用此代码我想在用户点击按钮时将其变为当它首先验证他们想要下载该文件,如果它们单击是,它会从$减去100个点用户点(然后更新mysql表,但我知道如何做到这一点),我需要帮助的是让代码在有人点击按钮时运行。此外,我想给他们下载没有他们得到他们可以重用的网址。要么没有显示他们的网址或使其成为唯一的一次性代码。在按钮上运行PHP并单击隐藏下载链接
<?php
//If submit form was clicked
if(isset($_POST['submit'])) {
//Server side validation for security purposes
if($userpoints >= 100) {
mysqli_query($con,"UPDATE users SET points = points - 100 WHERE users.user_name = '$username' LIMIT 1");
$filename = 'ibelongwithyou.mp3';
$filepath = '/home4/saintfiv/downloads/';
header("Content-Length: ".filesize($filepath.$filename));
header("Content-Disposition: attachment; filename=I Belong With You.mp3");
readfile($filepath.$filename);
}else {
header("Location: index.php?error=1");
}
}
?>
<form method="post" action="index.php">
<?php
if ($userpoints >= 100) {
echo '<input type="submit" name="submit" value="100pts">';
} else {
echo '<input type="submit" name="submit" value="100pts" disabled title="You need at least 100 points for this download">';
}
if(isset($_GET['error']) && $_GET['error'] == 1) {
echo "Error, you must have atleast 100points";
}
?>
</form>
有了这个更新后的代码,它似乎仍然在刷新后注册点击提交。还有一些奇怪的事情发生在一堆随机字符中,这些字符只是沿着页面向下。
我想通了,用头下载的一部分,所以我需要的是如何得到它当有人点击该按钮运行帮助最主要的 – 2013-04-07 06:20:35
请提供下载链接,例如路径为你下载...或者,如果它是基于数据库表,然后显示我的下载表字段 – daison12006013 2013-04-07 06:32:04
我更新了我的代码,你能看到发生了什么,我做了一个测试帐户,以便你可以看到发生了什么,saint57records.com/奖励用户名:测试密码:测试。我只有第一轨上的代码,当你点击它时,它会记录减去数据库中的点数,但是我没有下载并且出现所有奇怪的字符。 – 2013-04-07 06:58:36