Gurpreet Singh
Gurpreet Singh

Reputation: 163

Force to include file from same directory and not include_path

I am trying to use FPDF_Code39 class to print bar codes that extends the FPDF class. I am getting this error:

Warning (2): include(helveticab.php) [function.include]: failed to open stream: No such file or directory [D:\xampp\php\PEAR\fpdf.php, line 541]

The catch is in D:\xampp\php\PEAR\fpdf.php. It is including fpdf.php from the PEAR whereas I want it to include fpdf from the same directory as FPDF_Code39 class as I have the latest FPDF there.

I confirmed this issue by temporarily renaming PEAR/fpdf.php and everything works like a charm.

How do I force it to pick up FPDF from the same directory rather than include_path? Here is the require's that I have...

require('./fpdf.php'); \\I read at many places that this will do it.
require(dirname(__FILE__).'/fpdf.php');
require('fpdf.php')

Your help is really appreciated...

Upvotes: 7

Views: 16510

Answers (1)

Fabian Schmengler
Fabian Schmengler

Reputation: 24551

The second one is the most stable because it does not depend on the include path (like the third) nor on the current working directory (like the first).

Since PHP 5.3 you can also write

require __DIR__ . '/fpdf.php';

instead

require dirname(__FILE__).'/fpdf.php';

Upvotes: 16

Related Questions