Professional Web Applications Themes

include problem - PHP Development

Hi, I have a weird problem which must be stupid for sure. I'm trying to do an include in my code run as a cgi. The include works fine in the form: include ("directory/file"); even it works as: include ("directory/../directory/file"); but it doesn't work as: include ("./directory/file"); nor include ("../current/directory/file"). Of course, the obvious thinking is I have a perms problem but they are the same for '.' and for 'directory' so it makes no sense for me (755 if you wonder). If I execute the script it works without problem but it doesn't upon web request reporting: Warning: main(./db/db.tables.php) ...

  1. #1

    Default include problem


    Hi,

    I have a weird problem which must be stupid for sure. I'm trying to do
    an include in my code run as a cgi. The include works fine in the
    form:

    include ("directory/file");

    even it works as:

    include ("directory/../directory/file");

    but it doesn't work as:

    include ("./directory/file");

    nor

    include ("../current/directory/file").


    Of course, the obvious thinking is I have a perms problem but they are
    the same for '.' and for 'directory' so it makes no sense for me (755
    if you wonder).

    If I execute the script it works without problem but it doesn't upon
    web request reporting:

    Warning: main(./db/db.tables.php) [function.main]: failed to create stream: No
    such file or directory in /home/psanchez/tests/hola.php on line 8

    Warning: main() [function.main]: Failed opening './db/db.tables.php' for
    inclusion (include_path='.') in /home/psanchez/tests/hola.php on line 8


    I need to know what the problem is because I have a software that
    should work but it doesn't.

    Any ideas?

    Thanks

    Pablo S. Torralba
    Pablo Guest

  2. #2

    Default Re: [PHP] include problem

    Few days ago I asked the same question and got several excellent answers
    that helped me to solve the same problem - check the mailing list for
    'including files from different sub directories' on 24-10-2003.

    Nevertheless all those suggestions helped me to solve the problem from a
    normal browser point of view, I still have some troubles with avoiding
    the same error messages while editing my php staff, that means the
    development environment which I use (Eclipse + some plugins) can't
    handle the include/require directives correctly.

    Perhaps you may face the same issue .. ??

    Allex


    Pablo S. Torralba wrote: 
    Allex Guest

  3. #3

    Default include problem

    i have a page that INCLUDES another page but when the second page is
    included all the images are not showing.

    it is because the image url's are relative not absolute so the page is
    looking for the images relative to the main page location not the include
    page location - i dont want to have to change all the url's for the images -
    is there a way around this

    thanks in advance



    chris Guest

  4. #4

    Default Re: include problem

    "chris" <com> wrote in message
    news:3fe126c9$arach.net.au... 
    images - 


    You answered your own question.
    The image paths must be relative to the script that is trying to display
    them.

    and DONT cross post.

    Regards
    Richard Grove

    http://shopbuilder.org - ecommerce systems
    Become a Shop Builder re-seller:
    http://www.affiliatewindow.com/affiliates/merchantdetails.php?mid=611
    http://www.affiliatewindow.com/a.pl?590






    Richard Guest

  5. Moderated Post

    Default Re: include problem

    Removed by Administrator
    Shawn Wilson Guest
    Moderated Post

  6. #6

    Default Re: include problem

    "chris" <someonehere.com> schrieb im Newsbeitrag
    news:3fe126c9$1funnel.arach.net.au...
    > i have a page that INCLUDES another page but when the second page is
    > included all the images are not showing.
    >
    > it is because the image url's are relative not absolute so the page is
    > looking for the images relative to the main page location not the include
    > page location - i dont want to have to change all the url's for the
    images -
    > is there a way around this
    >
    > thanks in advance
    >
    If the included page contains the whole HTML page as in:

    if(isset($_POST['something'])) {
    do something;
    include("otherpage.php");
    exit;
    }
    else {
    display page;
    }

    you could easily use

    header("Location: otherpage.php");

    instead of the include command. Like that the url of the page you display
    corresponds to the actual place where the file is stored, so you don't have
    a relative path problem.

    HTH
    Markus


    Markus Ernst Guest

  7. Moderated Post

    Default Re: include problem

    Removed by Administrator
    chris Guest
    Moderated Post

  8. #8

    Default include problem


    Hi,

    Don't know if anyone can help - I've a problem with an include statement on
    one of the pages. Everything works fine on my local computer but when I
    upload to the live site, one of the include files doesn't get included at
    all. The wierd thing is that the includes at the top of the page work ok.
    <?php
    require_once("./config/owl.php");
    include_once("./lib/header.inc");
    ....
    .... lots of code
    ....
    include("./lib/footer.inc");
    ?>

    Is there any reason why the last statement won't work (since it works
    locally, there aren't any server settings about include files are there) -
    I've tried the obvious and made sure that the file is actually there.

    Andy.


    Andy Ralph Guest

  9. #9

    Default Re: include problem

    "Andy Ralph" <andrew_ralphNOSPAM> wrote in message
    news:41613ea9$0$8476$cc9e4d1fnews.dial.pipex.com. ..
    >
    > Hi,
    >
    > Don't know if anyone can help - I've a problem with an include statement
    > on
    > one of the pages. Everything works fine on my local computer but when I
    > upload to the live site, one of the include files doesn't get included at
    > all. The wierd thing is that the includes at the top of the page work ok.
    > <?php
    > require_once("./config/owl.php");
    > include_once("./lib/header.inc");
    > ....
    > .... lots of code
    > ....
    > include("./lib/footer.inc");
    > ?>
    >
    > Is there any reason why the last statement won't work (since it works
    > locally, there aren't any server settings about include files are there) -
    > I've tried the obvious and made sure that the file is actually there.
    >
    > Andy.
    >
    >
    Andy,

    Try it without "lots of code" - just the require, include, include. If it
    is included, your "lots of code" is breaking.

    G


    George King Guest

  10. #10

    Default Re: include problem

    Hi Andy,

    I don't know if you already checked this but just in case:

    When your local computer is a windows machine (probably) and the server
    is running linux (probably), you have to take in mind that the linux
    filesystem is casesensitive, and windows filesystems (FAT/FAT32/NTFS)
    are not. The only reason I can think of for this problem is that the
    footer.inc file has some uppercases in its filename (for example
    Footer.inc or footer.INC).

    Harrie

    Andy Ralph wrote:
    > Hi,
    >
    > Don't know if anyone can help - I've a problem with an include statement on
    > one of the pages. Everything works fine on my local computer but when I
    > upload to the live site, one of the include files doesn't get included at
    > all. The wierd thing is that the includes at the top of the page work ok.
    > <?php
    > require_once("./config/owl.php");
    > include_once("./lib/header.inc");
    > ....
    > .... lots of code
    > ....
    > include("./lib/footer.inc");
    > ?>
    >
    > Is there any reason why the last statement won't work (since it works
    > locally, there aren't any server settings about include files are there) -
    > I've tried the obvious and made sure that the file is actually there.
    >
    > Andy.
    >
    >
    Harrie Verveer Guest

  11. #11

    Default 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 p 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


    John Guest

  12. #12

    Default Re: Include problem

    > I am setting up a number of web pages and need to use an include with 

    You should probably use $_SERVER['PHP_SELF'] or $_SERVER['PATH_TRANSLATED'] or
    $_SERVER['SCRIPT_NAME'] or $_SERVER['SCRIPT_FILENAME'] 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
    Hilarion Guest

  13. #13

    Default Re: Include problem

    John wrote: 

    John,

    $_SERVER['DOENT_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['DOENT_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.
    net
    ==================
    Jerry Guest

  14. #14

    Default Re: Include problem

    On Thu, 01 Sep 2005 15:08:20 +0100, John <asdvfasdasdfvrfg> wrote:
     

    That did it, all works fine now.

    Thanks guys I appreciate the help.

    --
    John
    John Guest

Similar Threads

  1. CF Include Problem
    By Glenn_Stern in forum Dreamweaver AppDev
    Replies: 2
    Last Post: April 25th, 01:01 PM
  2. PHP include problem? any idea?
    By Cartensy in forum PHP Development
    Replies: 3
    Last Post: September 24th, 01:47 PM
  3. problem with INCLUDE
    By Sylvain Perreault in forum PHP Development
    Replies: 2
    Last Post: September 11th, 02:28 PM
  4. [PHP] Problem with include();
    By Raditha Dissanayake in forum PHP Development
    Replies: 0
    Last Post: September 7th, 06:14 AM
  5. Php Include Problem
    By Stephen in forum PHP Development
    Replies: 0
    Last Post: July 22nd, 07:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139