[英]downloading pdf file using php and html link
i have written some code to select a row from a database and generate a link. 我已经写了一些代码从数据库中选择一行并生成链接。 the link is working ok but when i try to download the pdf i get this: 链接工作正常,但是当我尝试下载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œ
displaying on the page. 显示在页面上。
my code is: 我的代码是:
<?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);
}
?>
any ideas how i can make it download the file rather than try and display it in the browser. 我如何使它下载文件的任何想法,而不是尝试在浏览器中显示它。 please note, its a shared hosting server so i cannot make many changes on the actual server itself 请注意,它是一个共享的托管服务器,因此我无法在实际服务器本身上进行很多更改
Change the following: 更改以下内容:
header('Content-Disposition: inline; filename="' . $filename . '"');
to 至
header('Content-Disposition: attachment; filename="' . $filename . '"');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.