johndoe555
johndoe555

Reputation: 99

PHP - FPDI class not found in production environment

I am using FPDI on a PHP CMS to generate PDFs via a scheduler command. Everything works fine on my development environment (Debian 11), but when running the same code on production (Debian too), I get the following error:

Class 'setasign\Fpdi\Fpdi' not found | Error thrown in file /FPDF/src/Fpdi/MultiCell.php in line 5

structure Folder of FPDF (see attached screenshot)

structure folder

Here is my custom MultiCell.php class:

<?php

namespace setasign\Fpdi\MultiCell;

class MultiCell extends \setasign\Fpdi\Fpdi
{
...
}

Fpdi.php :

<?php

namespace setasign\Fpdi;

use setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException;
use setasign\Fpdi\PdfParser\PdfParserException;
use setasign\Fpdi\PdfParser\Type\PdfIndirectObject;
use setasign\Fpdi\PdfParser\Type\PdfNull;

class Fpdi extends FpdfTpl
{
    use FpdiTrait;
    use FpdfTrait;

    /**
     * FPDI version
     *
     * @string
     */
    const VERSION = '2.6.1';
}

autoload.php :

<?php

/**
 * This file is part of FPDI
 *
 * @package   setasign\Fpdi
 * @copyright Copyright (c) 2024 Setasign GmbH & Co. KG (https://www.setasign.com)
 * @license   http://opensource.org/licenses/mit-license The MIT License
 */

spl_autoload_register(static function ($class) {
    if (strpos($class, 'setasign\Fpdi\\') === 0) {
        $filename = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 14)) . '.php';
        $fullpath = __DIR__ . DIRECTORY_SEPARATOR . $filename;

        if (is_file($fullpath)) {
            /** @noinspection PhpIncludeInspection */
            require_once $fullpath;
        }
    }
});

How I load FPDI in my export command :

public function exportCommand() {
    require_once(ExtensionManagementUtility::extPath('myProject').'Resources/Private/FPDF/fpdf.php');
    require_once(ExtensionManagementUtility::extPath('myProject').'Resources/Private/FPDF/src/autoload.php');
    require_once(ExtensionManagementUtility::extPath('myProject').'Resources/Private/FPDF/src/Fpdi/MultiCell.php');

    ini_set('max_execution_time', 0);
    ini_set('memory_limit','-1');

    ...
}

what I’ve tried :

I renamed the directory from FPDF to Fpdi to match the namespace exactly. It did not fix the issue.

I checked case sensitivity on Linux. All folder and file names match their respective namespaces.

I tried to change my Multicell.php like this :

namespace setasign\Fpdi\MultiCell;

use setasign\Fpdi\Fpdi;

class MultiCell extends Fpdi
{...}

Any help would be greatly appreciated!

PS : My project don't use composer

Upvotes: -1

Views: 32

Answers (0)

Related Questions