TCPDF保存文件到文件夹?(TCPDF Save file to folder?)

2019-06-27 22:58发布

我使用TCPDF打印收据,然后将其与PHPMailer的发送给客户,但我有一个问题:

我不知道如何将文件保存成PDF。

我已经试过这样:

// reset pointer to the last page
$pdf->lastPage();

//Close and output PDF document
$pdf->Output('kuitti'.$ordernumber.'.pdf', 'I');
$this->Output("kuitit");

Answer 1:

试试这个

$pdf->Output('kuitti'.$ordernumber.'.pdf', 'F');


Answer 2:

这个保存生成的PDF文件在您的项目中的自定义文件夹

$filename= "{$membership->id}.pdf"; 
$filelocation = "D:\\wamp\\www\\project\\custom";//windows
$filelocation = "/var/www/project/custom"; //Linux

$fileNL = $filelocation."\\".$filename;//Windows
$fileNL = $filelocation."/".$filename; //Linux

$this->pdf->Output($fileNL, 'F');


Answer 3:

$pdf->Output()需要一个第二参数$dest ,它接受一个单独的字符。 默认, $dest='I'打开浏览器的PDF。

使用F保存到文件

$pdf->Output('/path/to/file.pdf', 'F')


Answer 4:

只有那些为我工作的事情:

// save file
$pdf->Output(__DIR__ . '/example_001.pdf', 'F');
exit();


Answer 5:

对于谁是有存储文件困难,路径必须是通过根的所有道路。 例如,我的是:

$pdf->Output('/home/username/public_html/app/admin/pdfs/filename.pdf', 'F');


Answer 6:

$pdf->Output( "myfile.pdf", "F");

TCPDF错误:无法创建输出文件:myfile.pdf

include/tcpdf_static.php文件约2435行静态函数fopenLocal如果我删除了完整的“if语句”它工作正常。

public static function fopenLocal($filename, $mode) {
    /*if (strpos($filename, '://') === false) {
        $filename = 'file://'.$filename;
    } elseif (strpos($filename, 'file://') !== 0) {
        return false;
    }*/
    return fopen($filename, $mode);
}


Answer 7:

nick's example saves it to your localhost.
But you can also save it to your local drive.
if you use doublebackslashes:

 $filename= "Invoice.pdf"; 
 $filelocation = "C:\\invoices";  

 $fileNL = $filelocation."\\".$filename;
 $pdf->Output($fileNL,'F');

 $pdf->Output($filename,'D'); // you cannot add file location here

P.S. In Firefox (optional) Tools> Options > General tab> Download >Always ask me where to save files



Answer 8:

TCPDF使用fopen()来保存文件。 传递给TCPDF的任何路径Output()从而函数应该是绝对路径。

如果您想保存到一个相对路径,使用例如__DIR__全局常量(见这个答案 )。



Answer 9:

如果你仍然得到

TCPDF错误:无法创建输出文件:myfile.pdf

你能避免TCPDF的文件通过把PDF数据变量和保存这个字符串的文件保存逻辑:

$pdf_string = $pdf->Output('pseudo.pdf', 'S');
file_put_contents('./mydir/myfile.pdf', $pdf_string);


Answer 10:

您可以尝试;

$this->Output(/path/to/file);

所以对你来说,它就会像;

$this->Output(/kuitit/);  //or try ("/kuitit/")


文章来源: TCPDF Save file to folder?
标签: php tcpdf