我写了一些代码从数据库中选择一行并生成一个链接。链接工作正常,但当我试图下载PDF时,我看到这个:
����)�^�z8��AQ�[��rr�=��73KJ��KR]�PD�H�����>3;,;~˾����ɫS����/ؤ���,������=??<8��3��L�����e�'I�aN�i.����A�.�����������|x�F�oN���1>MʙJ�#�Mz�'�N��?K��sx`D�5gژ�r&�N3��M�f����߱9<]R��,))�dj���D@k&O-�7V����M��d�I��HMN=��9��/�ubS���`189'S�����f�p_��T�T�&ӭ���E>�O�)eAœ
显示在页面上。
我的代码是:<?php
$sql="SELECT * from table1 where invoice_number = '".$_GET["inv"]."' and sequence = '".$_GET["seq"]."' ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
if(mysql_num_rows($rs) > 0)
{
$result=mysql_fetch_array($rs);
$file = 'http://www.domain.co.uk/invoices/'.$result["pdf"].'';
$filename = 'Custom file name for the.pdf'; /* Note: Always use .pdf at the end. */
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);
}
?>
我知道如何让它下载文件,而不是尝试在浏览器中显示它。请注意,这是一个共享的主机服务器,所以我不能在实际的服务器上做很多改变
修改以下内容:
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Disposition: attachment; filename="' . $filename . '"');