root path doesn't work with php include

后端 未结 8 1576
天命终不由人
天命终不由人 2020-12-03 00:56

/ in the beginning of a link to get to the root folder doesn\'t work in php include.

for example \"/example/example.php\"

What is the solution?

相关标签:
8条回答
  • 2020-12-03 01:27

    I'm assuming by root folder you mean your web document root, rather than filesystem root.

    To that end, you can either

    • add the web root folder to the include path, and include('example/example.php')
    • or you can include($_SERVER['DOCUMENT_ROOT'].'/example/example.php')
    0 讨论(0)
  • 2020-12-03 01:27

    Every web server has a public_html folder, in which you usually keep your files etc. By using /, you will not get to public_html, instead you direct towards the main (unaccesible) root. So, use $_SERVER['DOCUMENT_ROOT']."/your/locati.on" instead

    0 讨论(0)
提交回复
热议问题