Include problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Include problem

    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


  • Hilarion

    #2
    Re: Include problem

    > I am setting up a number of web pages and need to use an include with[color=blue]
    > 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
    > [snip]
    > if I past these lines into the html outside of an include all
    > works fine.[/color]

    You should probably use $_SERVER['PHP_SELF'] or $_SERVER['PATH_TRANSLATE D'] or
    $_SERVER['SCRIPT_NAME'] or $_SERVER['SCRIPT_FILENAM E'] instead of __FILE__.
    "__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 ';
    or
    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.


    Hilarion

    Comment

    • Jerry Stuckle

      #3
      Re: Include problem

      John wrote:[color=blue]
      > 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
      >
      >[/color]

      John,

      $_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.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • John

        #4
        Re: Include problem

        On Thu, 01 Sep 2005 15:08:20 +0100, John <asdvfasd@asdfv rfg> wrote:
        [color=blue]
        >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.[/color]

        That did it, all works fine now.

        Thanks guys I appreciate the help.

        --
        John

        Comment

        Working...