Can't include or require an absolute path

后端 未结 1 979
难免孤独
难免孤独 2020-12-22 11:04

Apache version on server: 2.2.26

PHP version on server: 5.5.9

I have a file called admin_config.php in a folder, which has an .htaccess

相关标签:
1条回答
  • 2020-12-22 11:37

    Paths you give to include or require are paths on the local filesystem. They are not what you see in URLs to access your site. An absolute path starting with / is from the root of the filesystem. In Windows terms, /foo is C:\foo\. Relative paths like foo/bar are relative to the the PATH configuration variable, which depends on how your PATH is set up which also includes which PHP file was invoked.

    It's typically not a good idea to use absolute paths, since those are likely different on different systems (as you are experiencing). On your local machine the site may live in C:\core\..., but on the server it'll be running in /var/www/mysite/core/.... PATHs can also be cumbersome to work with. The best is typically to use __DIR__ or __FILE__ magic constants to construct an absolute path relative to the current file (if that made sense):

    require __DIR__ . '/some/folder/file.php`;
    

    This includes the file some/folder/file.php relative to the file in which it is written.

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