Force to include file from same directory and not include_path
13,768
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';
Author by
Gurpreet Singh
Updated on June 21, 2022Comments
-
Gurpreet Singh almost 2 years
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 includingfpdf.php
from thePEAR
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...
-
Gurpreet Singh over 11 yearsI am still getting the same error with
require __DIR__ . '/fpdf.php';
. -
Fabian Schmengler over 11 yearsThen something else is wrong. This
require
will never load anything from the include path. -
Fabian Schmengler over 11 yearsStart debugging. First step would be something like
echo 'now including ' . __DIR__ . '/fpdf.php';
right before therequire
-line