Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php TCPDF是否将文件保存到文件夹?_Php_Tcpdf - Fatal编程技术网

Php TCPDF是否将文件保存到文件夹?

Php TCPDF是否将文件保存到文件夹?,php,tcpdf,Php,Tcpdf,我正在使用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"); 你可以试试 $this-

我正在使用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");
你可以试试

$this->Output(/path/to/file);
所以对你来说,它就像

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

$pdf->Output('kuitti'.$ordernumber.'.pdf', 'F');
$pdf->Output()
接受第二个参数
$dest
,该参数接受单个字符。默认情况下,
$dest='I'
会在浏览器中打开PDF

使用
F
保存到文件

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

nick的示例将其保存到您的本地主机。
但您也可以将其保存到本地驱动器。
如果使用双反斜杠:

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

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

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

注意:在Firefox(可选)工具>选项>常规选项卡>下载>始终询问我保存文件的位置

这将生成的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');

对于存储文件有困难的用户,路径必须一直通过root。例如,我的是:

$pdf->Output('/home/username/public_html/app/admin/pdfs/filename.pdf', 'F');
TCPDF用于保存文件。 因此,传递到TCPDF的
Output()
函数的任何路径都应该是绝对路径


如果要保存到相对路径,请使用例如
\uuuu DIR\uuu
全局常量(请参阅)。

唯一对我有效的方法:

// save file
$pdf->Output(__DIR__ . '/example_001.pdf', 'F');
exit();
TCPDF错误:无法创建输出文件:myfile.pdf

include/tcpdf_static.php
文件中,静态函数
fopenLocal
中大约2435行,如果我删除完整的“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);
}
如果你还有

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

通过将PDF数据放入变量并将此字符串保存到文件中,可以避免TCPDF的文件保存逻辑:

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

这对我很有用,保存到根目录下的child dir(
temp\u pdf
):

$sFilePath = $_SERVER['DOCUMENT_ROOT'] . '//temp_pdf/file.pdf' ;
$pdf->Output( $sFilePath , 'F');

请记住使目录可写。

Hi。您希望将pdf保存到何处?您的服务器或其他地方?@blasteralfred在我的服务器上的文件夹
kuitit
工作:)我将尝试将其保存到文件夹中。@coosal这会引发错误
TCPDF错误:无法创建输出文件:../invoice\u job\u 6.pdf
@RNKushwaha是否检查文件夹权限?请为目标文件夹启用写入权限。它有755权限,但@developer的回答最终帮助了我。但它需要检查它的linux服务器(我的客户端的live服务器在linux主机上)还是windows服务器(我的本地主机在windows上)。如果它是在linux上,那么我使用了$\u ENV['DOCUMENT\u ROOT'],它希望文件路径来自主库文件所在的文件夹。或者使用绝对路径,您可以使用$\u ENV['DOCUMENT\u ROOT']找到它,然后确保它是可写的。使用“F”参数生成文件,“I”用于在同一页面中加载输出。文档没有明确说明这些问题。实际上,它已经需要扩展和折叠问题,但需要将其保存到服务器,然后将其发送给用户。该问题是旧问题,并且有一个可接受的答案。不需要回答,是的。。但是我没有把pdf文件放到我需要的文件夹里。有答案。所以,我想这对将来的人会有帮助的。唉。。。对,你不能直接把文件夹写到这里
$pdf->Output('/location/folder/'.$name'..pdf'.'F')
但它对我有用。。我在电子邮件中以附件的形式发送。。一旦它被生成。我也这样做了,我没有问题适应。为了将来的参考,我定义了一个上传路径,并将其用作
$pdf->输出(上传路径。'example_001.pdf','FI')相对路径工作正常。如果他们没有,那可能是一个错误的配置。谢谢,伙计,这也是唯一对我有用的东西。非常感谢,伙计!
$sFilePath = $_SERVER['DOCUMENT_ROOT'] . '//temp_pdf/file.pdf' ;
$pdf->Output( $sFilePath , 'F');