PHP - Class 'Fpdi' 未找到但包含定义它的文件
PHP - Class 'Fpdi' not found but the file defining it is included
您好,我正在使用 Fpdi class 在 pdf 文件中添加图像(在 PHP 中)(我从 github https://github.com/Setasign/FPDI 下载代码)
但是当我尝试实例化一个新的 Fpdi 时,出现错误:Class 'Fpdi' not found at line $pdf = new Fpdi();
这是我的代码:
<?php
//I don't get any error like require_once(): Failed opening required so I guess the files exist
require_once "fpdf.php";
require_once "FPDI/src/autoload.php";
require_once "FPDI/src/Fpdi.php";
$test = new FPDF();
echo '<br><br>';
//no probleme here
var_dump($test);
echo '<br><br>';
//I can see the files I want to include (fpdf.php,FPDI/src/autoload.php,/FPDI/src/Fpdi.php,FPDI/src/FpdfTpl.php,FPDI/src/FpdiTrait.php)
print_r(get_required_files());
echo '<br><br>';
//error here
$pdf = new Fpdi();
$pdf->AddPage();
$pdf->setSourceFile("commentaires.pdf");
$template = $pdf->importPage(1);
$pdf->useTemplate($template);
$pdf->Image('test.jpg', 1, 1, 200, 200);
$pdf->Output();
?>
有人可以帮我吗?
提前致谢
检查 class 上的名称空间。您可能需要在实例化时包含它。查看回购协议,这应该有效。
$pdf = new \setasign\Fpdi\Fpdi();
您好,我正在使用 Fpdi class 在 pdf 文件中添加图像(在 PHP 中)(我从 github https://github.com/Setasign/FPDI 下载代码)
但是当我尝试实例化一个新的 Fpdi 时,出现错误:Class 'Fpdi' not found at line $pdf = new Fpdi();
这是我的代码:
<?php
//I don't get any error like require_once(): Failed opening required so I guess the files exist
require_once "fpdf.php";
require_once "FPDI/src/autoload.php";
require_once "FPDI/src/Fpdi.php";
$test = new FPDF();
echo '<br><br>';
//no probleme here
var_dump($test);
echo '<br><br>';
//I can see the files I want to include (fpdf.php,FPDI/src/autoload.php,/FPDI/src/Fpdi.php,FPDI/src/FpdfTpl.php,FPDI/src/FpdiTrait.php)
print_r(get_required_files());
echo '<br><br>';
//error here
$pdf = new Fpdi();
$pdf->AddPage();
$pdf->setSourceFile("commentaires.pdf");
$template = $pdf->importPage(1);
$pdf->useTemplate($template);
$pdf->Image('test.jpg', 1, 1, 200, 200);
$pdf->Output();
?>
有人可以帮我吗?
提前致谢
检查 class 上的名称空间。您可能需要在实例化时包含它。查看回购协议,这应该有效。
$pdf = new \setasign\Fpdi\Fpdi();