php TCPDF 将文件保存到文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12304553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TCPDF Save file to folder?
提问by kushalbhaktajoshi
I'm using TCPDF to print a receipt and then send it to customer with phpMailer, but I have a problem:
我正在使用 TCPDF 打印收据,然后使用 phpMailer 将其发送给客户,但我遇到了一个问题:
I have no idea how to save the file into a pdf.
我不知道如何将文件保存为 pdf。
I've tried this:
我试过这个:
// reset pointer to the last page
$pdf->lastPage();
//Close and output PDF document
$pdf->Output('kuitti'.$ordernumber.'.pdf', 'I');
$this->Output("kuitit");
回答by kushalbhaktajoshi
try this
尝试这个
$pdf->Output('kuitti'.$ordernumber.'.pdf', 'F');
回答by Developer
this stores the generated pdf file in your custom folder of your project
这会将生成的 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');
回答by nick
$pdf->Output()takes a second parameter $dest, which accepts a single character. The default, $dest='I'opens the PDF in the browser.
$pdf->Output()接受第二个参数$dest,它接受单个字符。默认情况下,$dest='I'在浏览器中打开 PDF。
Use Fto save to file
使用F保存到文件
$pdf->Output('/path/to/file.pdf', 'F')
回答by user1477388
Only thing that worked for me:
唯一对我有用的东西:
// save file
$pdf->Output(__DIR__ . '/example_001.pdf', 'F');
exit();
回答by CIRCLE
For who is having difficulties storing the file, the path has to be all the way through root. For example, mine was:
对于存储文件有困难的人,路径必须一直通过 root。例如,我的是:
$pdf->Output('/home/username/public_html/app/admin/pdfs/filename.pdf', 'F');
回答by Jamy Mahabier
TCPDF uses fopen()to save files.
Any paths passed to TCPDF's Output()function should thus be an absolute path.
TCPDF 用于fopen()保存文件。因此,任何传递给 TCPDFOutput()函数的路径都应该是绝对路径。
If you would like to save to a relative path, use e.g. the __DIR__global constant (see this answer).
如果您想保存到相对路径,请使用例如__DIR__全局常量(请参阅此答案)。
回答by Atul Baraiya
$pdf->Output( "myfile.pdf", "F");
TCPDF ERROR: Unable to create output file: myfile.pdf
TCPDF 错误:无法创建输出文件:myfile.pdf
In the include/tcpdf_static.phpfile about 2435 line in the static function fopenLocalif I delete the complete 'if statement' it works fine.
在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);
}
回答by KarlosFontana
nick's example saves it to your localhost.
But you can also save it to your local drive.
if you use doublebackslashes:
nick 的示例将其保存到您的本地主机。
但您也可以将其保存到本地驱动器。
如果您使用双反斜杠:
$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
PS 在 Firefox 中(可选)工具>选项>常规选项卡>下载>总是询问我在哪里保存文件
回答by Mesa
If you still get
如果你仍然得到
TCPDF ERROR: Unable to create output file: myfile.pdf
TCPDF 错误:无法创建输出文件:myfile.pdf
you can avoid TCPDF's file saving logic by putting PDF data to a variable and saving this string to a file:
您可以通过将 PDF 数据放入变量并将此字符串保存到文件来避免 TCPDF 的文件保存逻辑:
$pdf_string = $pdf->Output('pseudo.pdf', 'S');
file_put_contents('./mydir/myfile.pdf', $pdf_string);
回答by blasteralfred Ψ
You may try;
你可以试试;
$this->Output(/path/to/file);
So for you, it will be like;
所以对你来说,它会像;
$this->Output(/kuitit/); //or try ("/kuitit/")

