尝试设置一个表,其中包含指向存储在MySQL表中的文件的链接。这是我写的代码。这是我第一次尝试使用PDO,所以我不确定它是否正确。
if(isset($_GET['ProposalNo']) && isset($_GET['UID']))
{
$fileget = $con->prepare("SELECT name, type, size, content FROM upload WHERE
ProposalNo = :proposalno AND UID = :uid");
$data = array('proposalno'=>$_GET['ProposalNo'],'uid'=>$_GET['UID']);
$fileget->execute($data);
list($name, $type, $size, $content) = $fileget->fetch(PDO::FETCH_ASSOC);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
exit;
}
以下是设置表格的代码:
$files = $con->prepare("SELECT UID, ProposalNo, name FROM upload");
$files->execute();
while($row = $files->fetch(PDO::FETCH_ASSOC))
{
$uid = $row['UID'];
$ProposalNo = $row['ProposalNo'];
$Name = $row['name'];
?>
<tr>
<td><?php echo "{$ProposalNo}</td>
<td><a href=gcaforms.php?ProposalNo={$ProposalNo}&UID={$uid}>{$Name}</a></td>";?>
</tr>
<?php }?>
当我滚动创建的链接时,ProposalNo和UID正确显示,但是当我点击它们时,他们只希望我打开或保存引用页面(gcaforms.php)。我错过了什么?
答案 0 :(得分:0)
解决。将$ fileget-&gt; fetch(PDO :: FETCH_ASSOC)更改为$ fileget-&gt;(PDO :: FETCH_BOTH)。