1

データベースから行を選択してリンクを生成するコードをいくつか書きました。リンクは正常に機能していますが、pdf をダウンロードしようとすると、次のようになります。

����)�^�z8��AQ�[��rr�=��73KJ��KR]�PD�H�����&gt;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�&amp;ӭ���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);
}
?>

ブラウザで表示しようとするのではなく、ファイルをダウンロードさせる方法を教えてください。共有ホスティング サーバーであるため、実際のサーバー自体に多くの変更を加えることはできません。

4

1 に答える 1

2

以下を変更します。

header('Content-Disposition: inline; filename="' . $filename . '"');

header('Content-Disposition: attachment; filename="' . $filename . '"');
于 2013-05-09T01:09:11.340 に答える