Include one PHP file into another

前端 未结 3 449
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 15:41

I need to include one PHP file into another. The PHP file that needs to be included sits in a separate directory though. This is how it is set up:

folder1/glo         


        
3条回答
  •  清歌不尽
    2020-12-18 16:41

    Your original include fails because... the relative path in your include is relative to the current directory, which in your case is not "folder1/folder2/". The current directory is likely to be the page from which you are serving your content.

    You need to either use an absolute path (with the help of $_SERVER['DOCUMENT_ROOT'] as in @Coomie's answer) or change your include_path to include the location of your included files (but then you must not use a relative path, but you wouldn't need to anyway).

提交回复
热议问题