【问题标题】:PHP - Class 'Fpdi' not found but the file defining it is includedPHP - 未找到“Fpdi”类,但包含定义它的文件
【发布时间】:2017-10-17 14:33:11
【问题描述】:

您好,我正在使用 Fpdi 类在 pdf 文件上添加图像(在 PHP 中)(我从 github https://github.com/Setasign/FPDI 下载了代码)

但是当我尝试实例化一个新的 Fpdi 时,我收到错误:$pdf = new Fpdi(); 行中找不到类“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();
?>

有人可以帮帮我吗?

提前谢谢你

【问题讨论】:

  • 你应该使用 composer 的自动加载和 use 语句

标签: php fpdf fpdi


【解决方案1】:

检查类的命名空间。您可能需要在实例化它时包含它。查看 repo,这应该可以工作。

$pdf = new \setasign\Fpdi\Fpdi();

【讨论】:

  • @RyanH 谢谢这个答案即使你刚刚从作曲家安装了一个包并且你没有在 laravel 的“app.php”中添加任何与这个包相关的东西
猜你喜欢
  • 2012-01-19
  • 2016-04-28
  • 2016-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-25
相关资源
最近更新 更多