dompdf输出文件名中的日期和时间。截至目前,它已经写了当前文件,我不想发生这种情况。我需要它保存为新文件,所以要在文件名末尾添加时间和日期,这将被读作新文件。
代码
private $curDir;
public function __construct() {
global $cur_dir;
$this->curDir = $cur_dir;
}
private function getHtml() {
ob_start();
include($this->curDir . '/quote-credit.php');
$retStr = ob_get_contents();
ob_end_clean();
return $retStr;
}
public function getPdf() {
$html = $this->getHtml();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream( "credit.pdf", array("Attachment" => 0));
$output = $dompdf->output();
$pdfFileName = $this->curDir.'/credit.pdf';
file_put_contents($pdfFileName, $output);
}
答案 0 :(得分:0)
也许这有点太明显了,我想念的是什么,但是怎么样......
$fn = sprintf('credit-%s.pdf', date('c'));
// ...
$dompdf->stream($fn, ['Attachment' => 0]);
// ...
$pdfFileName = $this->curDir . '/' . $fn;