Include problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am setting up a number of web pages and need to use an include with
the following code :

   require_once dirname(__FILE__) . '/HTML_ToPDF.php';
   $linkToPDFFull = $linkToPDF = tempnam(dirname(__FILE__), 'PDF-');

when this is inside an include statement the path is set to /tmp on
the file created which is wrong and I also get a parse error on the
second line - 'Cannot instantiate non-existent class' (although this
relates to something latter in the code).

However if I past these lines into the html outside of an include all
works fine.

Any ideas?

Thanks John

Re: Include problem

Quoted text here. Click to load it

You should probably use $_SERVER['PHP_SELF'] or $_SERVER['PATH_TRANSLATED'] or
"__FILE__" points always to the current (in this case included) file.
Check "Predefined Variables" chapter of PHP manual for detailed
description of those $_SERVER variables (or test them on your own) and choose
the one which is apropriate.
You can also use relative paths in includes like this:

require_once 'HTML_ToPDF.php';
require_once './HTML_ToPDF.php';

For "tempnam" function make sure, that the folder you are refering to
in the first parameter, exists. If it's not there (or in some cases when
the script is unable to create files in pointed folder), then the tempnam
result will be in system temporary folder. This may also be the cause
of your problems.


Re: Include problem

John wrote:
Quoted text here. Click to load it


$_SERVER['DOCUMENT_ROOT'] always points to the root directory of your web server  
(i.e. /var/www/html).  So you can use something like:

   require_once($_SERVER['DOCUMENT_ROOT'] . '/HTML_ToPDF.php');

in any directory and it will get the file.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Include problem

Quoted text here. Click to load it

That did it, all works fine now.

Thanks guys I appreciate the help.


Site Timeline