Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何添加带有特定文件id的下载链接?_Php_Html_Mysql_Download - Fatal编程技术网

Php 如何添加带有特定文件id的下载链接?

Php 如何添加带有特定文件id的下载链接?,php,html,mysql,download,Php,Html,Mysql,Download,如何添加包含特定文件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) {

如何添加包含特定文件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>";
}
//循环数据库查询结果并将其显示在表中
对于($i=$start;$i<$end;$i++)
{
//确保PHP不会试图显示不存在的结果
如果($i==$total\u结果)
{
打破
}
//将每行的内容回显到表中`
回声“;
echo'.mysql_result($result,$i,'fdesc')。';
echo'.mysql_result($result,$i,'category');
echo'.mysql_result($result,$i,'fdatein');
echo“”.mysql_result($result,$i,'username')。;
回声';
回声“;
}

给你,Pexter Volcome,我在mysqli中重写了它,与mysql没有太大区别,这是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>');
    }
?>

您还需要在d1.php中添加用于提供文件的代码。d1.php应该首先输出正确的http内容类型头,然后输出文件内容

警告:如果您只是在学习php,请不要学习过时的接口。这很糟糕,已经在PHP7中删除了。替换类和指南类有助于解释最佳实践。请确保您的用户参数是正确的,否则您将导致严重的后果。这种随意选择结果的方法效率极低,而且非常冗长。您应该只获取整行数据一次,然后直接使用该数据。我已经在它上面集成了一个分页,所以我为什么使用mysql_queryI不知道这意味着什么。它不会改变这样一个事实,即
mysql\u query
已经死了,您必须停止使用它。这不是辩论,这是由PHP核心团队决定的。无论你在做什么,PDO绝对是有办法做到的,在这个过程中你可能会为自己省去很多麻烦。另外,作为一个奖励,如果你修复了这个问题,这段代码将在PHP7中工作。它已经通过在db中获取结果工作了,但是我不知道在下载btn中传递id来获取文件
$downloadId = $_GET['id'];