• Hello,

    I have the FPDF library in a folder called fpdf and that folder is in my custom plugin folder. The problem is, whenever I try to use require('fpdf/fpdf.php'); to make use of it, I end up getting an error that no such file or directory exists. I really want to get it to work.

    Any idea why that’s happening?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The request is most likely looking for the folder in relation to a differnt folder, so it’s not finding it. The best way to make sure that it’s going to work is to use the full file path. Something like this:

    $file_uri = plugins_url( 'fpdf/fpdf.php', __FILE__ );

    That will ensure that you always get the correct URI for the file, and you can echo it out to see if it really is correct (I always like to add in some de-bugging in situations like this).

    Thread Starter admiralchip

    (@admiralchip)

    Thanks for your reply!

    I’ve tried what you suggested and I echoed it. The path is correct however it still says that the file cannot be found.

    Then the file isn’t where you think it is. If it was, the script would find it. :/

    Dion

    (@diondesigns)

    The plugins_url() function returns a URL. The PHP allow_url_include setting is usually disabled for security reasons. When the setting is disabled, attempting to use include() or require() on an HTTP stream will fail.

    If the fpdf.php file is located in the /fpdf subdirectory of the plugin, placing the following line as the first line of code in the plugin:

    define('MYPLUGIN_BASE_DIR', dirname(__FILE__));

    and using the following line to load the file:

    require(MYPLUGIN_BASE_DIR . '/fpdf/fpdf.php');

    will work. You can change MYPLUGIN_BASE_DIR to whatever you want.

    Thread Starter admiralchip

    (@admiralchip)

    Thanks for the code! I’ll try it as soon as possible and give feedback.

    Thread Starter admiralchip

    (@admiralchip)

    Nope, I tried it. It still doesn’t work. 🙁

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘require('fpdf/fpdf.php') not working in wordpress plugin?’ is closed to new replies.