我试图从不同文件夹中的 php 文件中获取我的“库”文件,但是在尝试从子文件夹访问它们时会出错。例如我有这样一个目录:
+ home
- file1.php
++ subfolder
- file2.php
++ libraries
- code_generator.php
- database_library.php
code_generator.php还依赖于其他库:
(LINE 25) require_once(realpath("./libraries/database_library.php"));
//this works fine when called from file1.php, but not from file2.php
我尝试从 ./subfolder/file2.php 调用 code_generator,例如:
chmod("../libraries/codegenerator.php", 0777); // for the error at the end of this question
require_once("../libraries/code_generator.php");
当我运行 file2.php 时,它会产生 2 个错误:
**Warning**: require_once(C:\xampp\htdocs\home\subfolder): failed to open stream: Permission denied in C:\xampp\htdocs\home\libraries\code_generator.php on line 25
**Fatal error**: require_once(): Failed opening required '' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\home\libraries\code_generator.php on line 25
*第 25 行是require_once(realpath("./libraries/database_library.php"));