0

我想显示一个链接到目录中文件的 PDF 图标,因为文件名与特定模式匹配。

我已经尝试使用下面的 PHP 脚本进行此操作,但我没有看到 PDF 图标,请告诉我哪里出错了。

提前致谢

PHP 脚本

<?php
require_once 'config.php';

$dbh = new PDO($dsn, $dbuser, $dbpass);

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$result = $dbh->query("
    SELECT a_aif.aif_id,
      a_aif.fee_source_id,
      a_aif.company_name_per_sedar,
      a_aif.document_filing_date,
      IF (a_aif_remaining.aif_id IS NULL, 0, 1) `match`
    FROM  a_aif
      LEFT JOIN a_aif_remaining
        ON a_aif_remaining.aif_id = a_aif.aif_id
    ORDER BY aif_id DESC");

$result->setFetchMode(PDO::FETCH_ASSOC);

$url = "http://www.theauditorsreport.com/_documents/fees/aifs/".$row[fee_source_id];
$imgsrc = "./images/pdf.gif";

?>

<table>
<tr>
    <th><b>Document ID</b></th>
    <th><b>Pubco Name</b></th>
    <th><b>Filing Date</b></th>
    <th><b>PDF</b></th>
</tr>
<?php foreach($result as $index => $row) : ?>
<tr data-recordId="<?=$row[fee_source_id];?>"
    class="<?=$row["match"] ? "match" : "";?>">
    <td><?php echo $row[fee_source_id]; ?></td>
    <td><?php echo $row[company_name_per_sedar]; ?></td>
    <td><?php echo $row[document_filing_date]; ?></td>
    <td><a href=<?php echo $url ?><img src=<?php echo $imgsrc ?></a></td>
</tr>
<? endforeach;?>
</table>
4

2 回答 2

1

此行似乎存在 HTML 错误:

<td><a href=<?php echo $url ?><img src=<?php echo $imgsrc ?></a></td>

然而,它缺少一些更正(主要是标签的引号和结尾<a>,以及<img>标签):

<td><a href="<?php echo $url ?>"><img src="<?php echo $imgsrc ?>"></a></td>

希望这可以为您指明正确的方向。

于 2013-01-07T05:49:52.653 回答
1

只需尝试以下操作:

<?php
require_once 'config.php';

$dbh = new PDO($dsn, $dbuser, $dbpass);

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$result = $dbh->query("
    SELECT a_aif.aif_id,
      a_aif.fee_source_id,
      a_aif.company_name_per_sedar,
      a_aif.document_filing_date,
      IF (a_aif_remaining.aif_id IS NULL, 0, 1) `match`
    FROM  a_aif
      LEFT JOIN a_aif_remaining
        ON a_aif_remaining.aif_id = a_aif.aif_id
    ORDER BY aif_id DESC");

$result->setFetchMode(PDO::FETCH_ASSOC);

$imgsrc = "./images/pdf.gif";

?>

<table>
<tr>
    <th><b>Document ID</b></th>
    <th><b>Pubco Name</b></th>
    <th><b>Filing Date</b></th>
    <th><b>PDF</b></th>
</tr>
<?php foreach($result as $index => $row) : ?>
<tr data-recordId="<?php echo $row['fee_source_id'];?>" class="<?php echo $row['match'] ? "match" : "";?>">
    <td><?php echo $row['fee_source_id']; ?></td>
    <td><?php echo $row['company_name_per_sedar']; ?></td>
    <td><?php echo $row['document_filing_date']; ?></td>
   <?php 
$filename = '/_documents/fees/aifs/'.$row['fee_source_id'].'.pdf';
if (file_exists($filename)) {?>
    <td><a href="http://www.theauditorsreport.com/_documents/fees/aifs/<?php echo $row['fee_source_id'].".pdf"; ?>" target="_blank" title="pdf<?php echo $row['fee_source_id']; ?>"><img border="0" title="pdf<?php echo $row['fee_source_id']; ?>" src="<?php echo $imgsrc; ?>" alt="pdf<?php echo $row['fee_source_id']; ?>" /></a></td>
<?php } else {?>
<td>&nbsp;</td>
<?php }?>
</tr>
<? endforeach;?>
</table>
于 2013-01-07T06:01:02.860 回答