Ok, so I am trying to use include_once and require_once....yay. Im not a n00b either btw....well...I also dont have all the functions down packed either ... w/e.

Anyways, I have a structure like this (which will not change).

/folder/for/config/config.php
/folder/modules/of/some/sort/index.php
/folder/index.php

Now, /folder/index.php can include /folder/config.php easily (I am not writing it out as this either:

include_once('/folder/for/config/config.php');

but rather like this

include_once('/for/config.php

Now I would like to have my /folder/modules/of/some/soft/index.php file include the config file in the same manner. I have tried

include_once('../../../for/config/config.php');

But that returns an error saying it can not find the file/folder.

Someone please help. 😕

    That wouldn't be the path. From /folder it would be '../folder/for/config/config.php'. Assuming /folder is the same /folder, the path would just be 'for/config/config.php'

    edit: Oops. I think I misread your post and what you're trying to do -- sorry.

      its like this (to make it easier):

      /folder/more/junk/here/file1.php
      /folder/file2.php

      I want file2.php to be able to include file1.php without writting out include('/more/file1.php') I want something like ../more/junk/here/file1.php

      Its better to see when the folders get deeper.

        include_once('../../../../for/config/config.php');
        

        ...(with an extra ../) would be an correct path that you need in this example:

        /folder/for/config/config.php
        /folder/modules/of/some/sort/index.php

        Or am I missing something?

          the exact example is not correct....leme try single quotes on my code instead of double...i will give you the exact error I get too....gimme a min.

            Here we go...

            Warning: main(../../includes/functions.php): failed to open stream: No such file or directory in /usr/local/apache/htdocs/hexxnet1/modules/def-news/index.php on line 3

            So what I am trying to include is 2 folders up and 2 folders down (how ever you WOULD say that) into another one.

            Here is the code:

            require_once('../../includes/functions.php');

              The file you are asking is there where you search for him...

              Only other option that comes to my mind is CHMOD...

              How are file permisiions set up like?

                Its NOT a server issue at all....its the way im trying to call it. I CAN include it if I type in the full server path, but I dont want it to be like that. I also dont want to use $_SERVER['DOCUMENT_ROOT'] or whatever the proper name for it is. Reason being, document root looks for the apache root. This current site is in another folder, so I am trying to make it as effortless as possible.

                I dont understand why a simple ../ doesnt work...grrrr.

                  Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of current script. E.g. if your include_path is ., current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/ and then in /www/include/. If filename begins with ../, it is looked only in include_path relative to the current working directory.

                  It's from the manual...

                    Originally posted by bodzan
                    It's from the manual...

                    Right, so wtf is wrong with my stuff? ../some/dir should bring me up one directory, and then go back down into ../some/dir so i can get the file needed.

                      I can't say that there IS anything wrong with your code! :bemused:

                      We need someone else's help because my ideas are gone...

                        Originally posted by bodzan
                        I can't say that there IS anything wrong with your code! :bemused:

                        We need someone else's help because my ideas are gone...

                        Sigh....

                          Hmmm. I'm a bit lost with all of these examples.

                          Any chance you can post the actual structure you're working with here? And also the exact include() from the script you're using?

                          That way, it's easier to visualize AND you get a solution suited just for your needs 😛

                            One more idea on this. Lets say your structure of folders is as follows:
                            - /home/index.php
                            - /home/scripts/mailerscript.php
                            -/home/includes/sendmail.php
                            If you for example need to include mailer script in sendmail.php the obvious thing to do would be to write

                            include('../scripts/mailerscript.php'); //this line in sendmail.php

                            But now, when you include sendmail.php in index.php, the current directory would be /home, not /home/includes/ and the include statement in sendmail.php will look for /scripts/mailerscript.php instead of /home/scripts/mailerscript.php.
                            Maybe the similar problem is with your includes. You need to write your paths in included files from the folder from which the main script operates (not where the actual include files exist)
                            Correct me if i'm wrong...

                              Originally posted by wilku
                              One more idea on this. Lets say your structure of folders is as follows:
                              - /home/index.php
                              - /home/scripts/mailerscript.php
                              -/home/includes/sendmail.php
                              If you for example need to include mailer script in sendmail.php the obvious thing to do would be to write

                              include('../scripts/mailerscript.php'); //this line in sendmail.php

                              But now, when you include sendmail.php in index.php, the current directory would be /home, not /home/includes/ and the include statement in sendmail.php will look for /scripts/mailerscript.php instead of /home/scripts/mailerscript.php.
                              Maybe the similar problem is with your includes. You need to write your paths in included files from the folder from which the main script operates (not where the actual include files exist)
                              Correct me if i'm wrong... [/B]

                              No I think you are right. Because this is the issue I am having 🙁

                              Time for some restructuring or something...beh.

                                Write a Reply...