在我的Xampp中我可以做到:
require_once('../myFile.php');
Run Code Online (Sandbox Code Playgroud)
它有效.
当我上传执行require_once的文件时,它不起作用.
这是服务器上的错误:
Warning: require_once(../myFile.php) [function.require-once]: failed to open stream: No such file or directory in /home/xxx/public_html/yyyy/testinclude.php on line 11
Fatal error: require_once() [function.require]: Failed opening required '../myFile.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxx/public_html/yyyy/testinclude.php on line 11
Run Code Online (Sandbox Code Playgroud)
任何的想法?
它不起作用的一个可能原因是你的文件框不完全相同.
在UNIX中,文件路径区分大小写.在WIN中不是这种情况.所以,如果你包括../myFile.php,你的文件必须是名字myFile.php,而不是myfile.php.
此外,include始终根据当前路径包含文件.考虑这两个文件.
/home/xxx/public_html/first.php
<?php include('dir/second.php'); ?>
/home/xxx/public_html/dir/second.php
<?php include('third.php'); ?>
Run Code Online (Sandbox Code Playgroud)
运行时first.php,第二个文件将包含/home/xxx/public_html/third.php.
dir/second.php直接运行时,它将包括/home/xxx/public_html/dir/third.php.
如果include必须始终相对于当前文件,请使用以下命令:
include(dirname(__FILE__) . '/third.php');
Run Code Online (Sandbox Code Playgroud)
使用上面的代码片段,无论当前目录如何,dir/second.php都将始终包含/home/xxx/public_html/dir/third.php.
| 归档时间: |
|
| 查看次数: |
4758 次 |
| 最近记录: |