如何添加包含特定文件 ID 的下载链接。
这是代码:
//loop through results of database query and displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results)
{
break;
}
// echo out the contents of each row into a table`
echo "<tr " . $cls . ">";
echo '<td>' . mysql_result($result, $i, 'fdesc') . '</td>';
echo '<td>' . mysql_result($result, $i, 'category') . '</td>';
echo '<td>' . mysql_result($result, $i, 'fdatein') . '</td>';
echo '<td class="blue-text text-darken-4"><strong>' . mysql_result($result, $i, 'username') . '</strong></td>';
echo '<td><a href="d1.php">Download</a></td>';
echo "</tr>";
}
你去 Pexter Volcome 我在 mysqli 中重写了它,根本没有太大的不同,这是 mysql 改进的,所以它没有那么多的安全漏洞。
<?php
$conn = new mysqli('host', 'user', 'pass', 'db');
$sqlpull = $conn->query("SELECT fdesc,category,fdatein,id from table");
while($row = $sqlpull->fetch_assoc()) {
echo('<tr '.$cls.">");
echo('<td>'.$row['fdesc'].'</td>');
echo('<td>'.$row['category'].'</td>');
echo('<td>'.$row['fdatein'].'</td>');
echo('<td class="blue-text text-darken-4"><strong>'.$row['username'].'</strong></td>');
echo('<td><a href="d1.php?id='.$row['id'].'">Download</a></td>');
echo('</tr>');
}
?>
当按钮被按下时,它将调用php文件下载,你需要的只是
$downloadId = $_GET['id'];
您还需要在 d1.php 中添加代码以提供文件。d1.php 应首先输出正确的 http 内容类型标头,然后输出文件内容