douduan4116 2019-03-05 18:51
浏览 199
已采纳

Laravel下载pdf返回随机字符

Im trying to download my earlier saved pdf.

Ive created this function.

    {
        $storagePath = BillingStorage::findOrFail($billingTypeId);
        $filename= $storagePath->name;
        $headers = [
            'Content-Type' => 'application/pdf',
            'Content-Disposition' => 'attachment; filename=' . $filename,
        ];

        $filepath= storage_path().'/pdf/billing/invoice/'.$filename.'.pdf';

        return response()->download($filepath,$storagePath->name,$headers);

    }


And it returns this:

%PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R >> /XObject << /I1 10 0 R /I2 11 0 R /I3 12 0 R /I4 13 0 R >> >> /MediaBox [
���mO�F���)F�
*�����j�� �����^����@����G��8v�<�Ȏ�;������=�sN����DHŸ����e�a��-�:�,���_'�1���
O �$�-\�QoI�zߓt�t���:H�ޘ�`�|��;M1��G��ouեa�2��3e q���O�M�� ���iN� �dɸ"Q̚()� ��#�� ɸ"Q� ]1U
J`�zG:_v�.�ۤwӯ k����n�۪���yc�k�|�۠��5G6�� ;Iu�A �>A��������Z���� (!�g�

Var dumping my $filepath is resulting in this : C:\laragon\www\YTBN\storage/pdf/billing/invoice/YTBN_Armando_3_2019-0305.pdf" Which is correct.

  • 写回答

1条回答 默认 最新

  • doucan957495 2019-03-05 19:04
    关注

    try to used like that

        $storagePath = BillingStorage::findOrFail($billingTypeId);
    
        $headers = [
            'Content-Type' => 'application/pdf',
        ];
    
        $filename = $storagePath->name.'.pdf'; //file name with extension add..
        $filepath = storage_path().'/pdf/billing/invoice/'.$filename;
    
        return response()->download($filepath,$filename,$headers);
    

    or u can used directly in laravel 5.5 file path only no need to set header

        return response()->download($filepath);  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题