【问题标题】:tcpdf wordpress error in PHP even tho i followed the tcpdf example 1by1即使我遵循 tcpdf 示例 1by1,PHP 中的 tcpdf wordpress 错误
【发布时间】:2019-07-23 09:09:58
【问题描述】:

我创建了一个插件,当你按下发送时,表格中的数据应该被翻译成 pdf 并保存在一个文件夹中以供备份。

我正在使用 tcpdf api,下载了库并将其放在我的插件文件夹中。当我尝试使用来自 tcpdf 站点的 givin textexample 对其进行测试时,它只会抛出这些错误:

“警告:“继续”定位开关等同于“中断”。确实 你的意思是使用“继续2”?在 /www/htdocs/w00e68de/msp.rfid-dresden.de/wp-content/plugins/wp-markenbuero/tcpdf/tcpdf.php 上线17778

警告:fopen():不支持远程主机文件访问, 文件://example_002.pdf 在 /www/htdocs/w00e68de/msp.rfid-dresden.de/wp-content/plugins/wp-markenbuero/tcpdf/include/tcpdf_static.php 在线 1854

警告:fopen(file://example_002.pdf):打开流失败:否 合适的包装可以在 /www/htdocs/w00e68de/msp.rfid-dresden.de/wp-content/plugins/wp-markenbuero/tcpdf/include/tcpdf_static.php 在第 1854 行 TCPDF 错误:无法创建输出文件: example_002.pdf"

// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf.php');

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

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$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);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', 'BI', 20);
// add a page
$pdf->AddPage();
// set some text to print
$txt = <<<EOD
TCPDF Example 002
Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
EOD;
// print a block of text using Write()
$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_002.pdf', 'F');
}
?>

【问题讨论】:

  • 1.确保您已启用 fopen 以打开 URL; 2. 这是警告,而不是错误。您可以关闭错误报告,它将被禁止。 3. 可能是插件不安全,实际上在文件 tcpdf.php 的第 17778 行抛出警告

标签: php wordpress tcpdf


【解决方案1】:

这有两个部分,所以我将把我的答案分成两部分:

文件协议警告/无法生成 PDF:

F 模式下调用Output 保存到本地文件时,不能使用相对文件路径。您必须提供完整的文件路径。以下是一些示例:

//Generates output file in the same folder as current script.
$pdf->Output(dirname(__FILE__).'/example_002.pdf', 'F');

//Save to the document root.
$pdf->Output($_SERVER['DOCUMENT_ROOT'].'/example_002.pdf', 'F');

继续定位开关警告:

此警告是PHP 7.3 incompatibility warning,无论您使用的是哪个版本的 TCPDF 库。 github repo 的 master 分支似乎没有抛出此警告,因此请尝试使用该版本的库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-26
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    相关资源
    最近更新 更多