我已经使用FPDF库开发了一个动态PDF。在电脑上一切正常,但在手机上,PHP文件开始下载,下载也会自动取消。
这是一个示例代码
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>如果我将此文件另存为"sample.php“并在计算机中查看,则打开该文件时没有任何错误,输出为"Hello World”。但是,如果我在任何android浏览器(Google chrome,Firefox for Android,Android浏览器)中查看页面,则下载的是sample.php文件,而不是查看PDF文件。
发布于 2017-08-13 02:01:39
问题是这个浏览器对你发送的头异常挑剔。如果每个元素之间的Content-Type头中有空格,Android将忽略它们。
<?php
require('fpdf/fpdf.php');
header('Content-type: application/download;filename="example.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
echo $pdf->Output('S');发布于 2020-04-13 05:12:53
$pdf->Output('I','name_file.pdf');https://stackoverflow.com/questions/45651577
复制相似问题