Php 如何在不下载的情况下查看pdf?

Php 如何在不下载的情况下查看pdf?,php,pdf,view,download,Php,Pdf,View,Download,大家好,我正在使用select命令查看数据库中的pdf。它正在工作,但每次刷新页面时,它都会尝试下载所有pdf。我希望它是一个正常的列表,然后下载一次点击 这是我的密码 <?php function selectFishprice() { try { $connection = connect(); $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

大家好,我正在使用select命令查看数据库中的pdf。它正在工作,但每次刷新页面时,它都会尝试下载所有pdf。我希望它是一个正常的列表,然后下载一次点击

这是我的密码

<?php
function selectFishprice()
{
    try {
        $connection = connect();
        $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sqlQuery = "SELECT price AS pdf_path, Date FROM upload WHERE id = 1";
        $statement = $connection->query($sqlQuery);
        $statement->setFetchMode(PDO::FETCH_ASSOC);
        $Fishprices = $statement->fetchAll();
        if (!empty($Fishprices)) {
            return $Fishprices;
        } else {
            return NULL;
        }
    } catch (PDOException $exception) {
        die("Error: " . $exception->getMessage());
    }
}

$fishPrices = selectFishprice();
?>
<table id="users">
    <thead>
        <tr>
            <th scope="col">Fish Market Price</th>
            <th scope="col">As of</th>
        </tr>
    </thead>
    <tbody>
<?php
    if (!empty($fishPrices)) {
        foreach ($fishPrices as $fishPrice) {
            $date = strtotime($fishPrice['Date']);
?>
            <tr class="table-primary">
            <td scope="row"><img src="<?= $fishPrice['pdf_path'] ?>"/></td>
            <td scope="row"><?= date('M j Y', $date)?></td>
            <?php
        }
    } else {
?>
        <tr class="table-primary">
            <td class="text-center" colspan="4" scope="row">No records found.</td>
        </tr>
<?php
    }
?>
    </tbody>
</table>

鱼市价格
截至
"/>
没有找到任何记录。
我从网站上读到要使用“标题”,但我不明白“标题”应该放在哪里?非常感谢您的帮助

函数selectFishprice()
{
试一试{
$connection=connect();
$connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常);
$statement=$connection->query(“选择价格,上传日期,其中id=1”);
$statement->setFetchMode(PDO::FETCH_ASSOC);
$Fishprices=$statement->fetchAll();
如果(!空($Fishprices)){
返回$fishprice;
}否则{
返回NULL;
}
}捕获(PDO异常$exception){
die(“错误:”.$exception->getMessage());
}
}
$fishPrices=选择FISHPRICE();
鱼市价格
截至
没有找到任何记录。

您完全没有显示任何与PDF相关的代码。您好。$fishPrice['price']包含PDF路径“price”只是表中字段的名称。那么为什么要将PDF文件的路径用作
img
元素的src?这将如何尝试“下载”有什么吗?因为我认为它与我制作的其他列表类似,无论如何,我现在用embed替换img元素。谢谢你指出。你想显示下载链接还是在你的页面中嵌入PDF?你的问题不清楚。谢谢。我已经用anchor标记替换了embed标记这意味着它不应该像图像一样对待。
function selectFishprice()
{
    try {
        $connection = connect();
        $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $statement = $connection->query("SELECT price, Date FROM upload WHERE id = 1 ");
        $statement->setFetchMode(PDO::FETCH_ASSOC);
        $Fishprices = $statement->fetchAll();
        if (!empty($Fishprices)) {
            return $Fishprices;
        } else {
            return NULL;
        }
    } catch (PDOException $exception) {
        die("Error: " . $exception->getMessage());
    }
}

$fishPrices = selectFishprice();

         <table id="users">
               <thead>
                    <tr>
                      <th scope="col">Fish Market Price</th>
                       <th scope="col">As of</th>
                        </thead>
                         <tbody>
                         <?php
                          if(!empty($fishPrices)) {
                             foreach ($fishPrices as $fishPrice) {
                                 $date = strtotime($fishPrice['Date']);
                              ?>
                             <tr class="table-primary">
                            <td scope="row"><a href ="<?= $fishPrice['price'] ?>" target="_blank"><img src="" alt="PDF"/></a></td>
                             <td scope="row"><?= date('M j Y', $date)?></td>
                             <?php
                             }
                           } else {
                             ?>
                           <tr class="table-primary">
                            <td class="text-center" colspan="4" scope="row">No records found.</td>
                                            </tr>
                                            <?php
                                        }
                                        ?>
                                        </tbody>
                                    </table>