TCPDF 未下载

TCPDF is not downloading

我使用 TCPDF 生成一些 PDF 文件并将其保存在 PC 上。但是它保存在我的网站文件夹所在的服务器上。
我需要将文件保存到 PC。当我在本地服务器 (OpenServer) 上工作时,它工作正常。 路径设置在 $_POST 中,因为我使用 AJAX 生成 pdf 如何解决?

代码:

require_once('tcpdf/tcpdf.php');


$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


$pdf->SetCreator('God');
$pdf->SetAuthor('God');
$pdf->SetTitle('Contract');
$pdf->SetSubject('Contract');

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

$pdf->setFontSubsetting(true);

$pdf->SetFont('dejavusans', '', 14, '', true);

$pdf->AddPage();

$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));

 ob_start();
        include "page1.php";
        $content = ob_get_clean();
$html = $content;

$pdf->writeHTML($html, true, false, true, false, '');
$pdf->AddPage();

 ob_start();
        include "page2.php";
        $content = ob_get_clean();
$html = $content;

$pdf->writeHTML($html, true, false, true, false, '');
$pdf->AddPage();

 ob_start();
        include "page3.php";
        $content = ob_get_clean();
$html = $content;


$pdf->writeHTML($html, true, false, true, false, '');
$pdf->AddPage();

$dirname = $_POST['dirname'];
$path = $_POST['path'] . $dirname . '\ ';
mkdir($path, 0700);

$filename = $_POST['filename'] . '.pdf';

$pdf->Output($path . $filename, 'F');

在最后一行,使用选项 'D' 而不是 'F':

$pdf->Output($path . $filename, 'F');

如文档中所述,

D: send to the browser and force a file download with the name given by name.
F: save to a local file with the name given by name (may include a path).