External config file outside of tcpdf/config/

Help
Grama
2011-06-09
2013-02-19
  • Grama
    Grama
    2011-06-09

    Is there an easy way to store an external config file outside of the
    tcpdf/config directory? having a config file in a seperage directory and
    importing with:
    require_once (__SITE_PATH . '/includes/my_tcpdf_config.php');
    // require_once('/var/www/tcpdf/config/my_tcpdf_config.php'); This works
    define ( 'K_TCPDF_EXTERNAL_CONFIG', true );
    require_once('/var/wwwi/tcpdf/tcpdf.php');
    Causes tcpdf to hang until php times out.

     
  • Nicola Asuni
    Nicola Asuni
    2011-06-09

    Be sure you are using the latest TCPDF version and check the example n. 19 for
    alternating configuration file usage.

     
  • Grama
    Grama
    2011-06-09

    Thanks for the quick reply.
    I'm using 5.9.88.
    changing the include path in the example_019.php file to point outside the
    tcpdf/config/ directory as follows:

    require_once('../config/lang/eng.php');
    // load alternative config file
    require_once('/var/www/dev/includes/my_tcpdf_config.php');
    define("K_TCPDF_EXTERNAL_CONFIG", true);
    require_once('../tcpdf.php');
    

    results in the same behavior.
    Apache hangs with no error log generated, CLI goes into an infinite loop.

    PHP Warning:  readdir() expects parameter 1 to be resource, boolean given in /var/www/tcpdf/tcpdf.php on line 4762
    
     
  • Nicola Asuni
    Nicola Asuni
    2011-06-13

    Check the file permissions for the alternative configuration file and check
    also the alternative configuration file for errors.
    From the error message seems that you are missing the definition of
    K_PATH_FONTS constant.

     
  • Grama
    Grama
    2011-06-14

    Alright, I've managed to track the problem to the begining of the tcpdf_config
    file.
    The line: $k_path_main = str_replace( '\', '/',
    realpath(substr(dirname(FILE), 0, 0-strlen('config'))));
    would fail to find the correct tcpdf directory which would not cause an error
    until the program went into an infinite loop on line 4762 of tcpdf.php.

    explicitly setting the K_PATH_MAIN in the config file fixed the problem for
    me.

    Thanks for the help

     
  • Szorstki
    Szorstki
    2011-06-16

    I've added

    define ( 'K_TCPDF_EXTERNAL_CONFIG', true );
    

    in my php file using TCPDF. I have only few new values defined for
    configuration (not all of them, used by TCPDF), so there should be error -
    right?
    But TCPDF is using values from standard configuration file in
    /config/tcpdf_config.php

    My TCPDF version: 5.9.088

     
  • Immo
    Immo
    2011-08-24

    results in the same behavior. Apache hangs with no error log generated, CLI
    goes into an infinite loop.

    PHP Warning: readdir() expects parameter 1 to be resource, boolean given
    

    in /var/www/tcpdf/tcpdf.php on line 4762

    To avoid the infinite loop in case of a non-existent/wrong configured fontpath
    an additional condition should be added to function "getFontsList":

        protected function getFontsList() {
            if($fontsdir = opendir($this->_getfontpath())) {
                while (($file = readdir($fontsdir)) !== false) {
                    if (substr($file, -4) == '.php') {
                        array_push($this->fontlist, strtolower(basename($file, '.php')));
                    }
                }
                closedir($fontsdir);
            }
        }
    

    HTH,
    Immo

     
  • Valentin Despa
    Valentin Despa
    2013-02-19

    +1 for getFontsList check

    @Grama I also had this problem with the infinite loop in the version 5.9.205 (loading config files outside tcpdf folders). And indeed, no error was given.

    Thank you for posting here your solutions, it saved me hours of debugging.

     
  • Nicola Asuni
    Nicola Asuni
    2013-02-19

    I will introduce the additional check on getFontsList() on the next release.