【问题标题】:including php files with exec-PHP包括带有 exec-PHP 的 php 文件
【发布时间】:2012-02-11 18:37:46
【问题描述】:

我安装并激活了execPHP插件并使用了这个

<?php echo "hello"; ?>
<?php include ("/test/test.php") ?>

在 wordpress 的 tinyMCE 中。

我可以看到正确输出的 hello,但随后我看到了这个错误;

警告:include(/test/test.php) [function.include]:无法打开流:D:\Hosting\5291199\html\sites\Main\wp-content\plugins\ 中没有这样的文件或目录exec-php\includes\runtime.php(42) : eval()'d 代码在第 3 行

警告:include() [function.include]:在 D:\Hosting\5291199\html\ 中打开 '/test/test.php' 以包含 (include_path='.;C:\php5\pear') 失败sites\Main\wp-content\plugins\exec-php\includes\runtime.php(42) : eval()'d code on line 3

我确定,/test/test.php 存在!它有有效的 php 代码...

【问题讨论】:

  • 只是为了确保您有一个文件D:\test\test.php?第一个/ 使它在根目录中查找它...

标签: php wordpress


【解决方案1】:

您必须使用完整路径

echo dir(__FILE__); // Find out in what folder you are
include (dirname(__FILE__) . "/../test/test.php"); // then adjust to the location of the file from this path

【讨论】:

  • 如果你有 PHP 5.3 或更高版本,你可以使用__DIR__ 常量。如果你有一个旧的 PHP 版本,你应该使用 dirname(__FILE__) dir(...) 返回一个 Directory 的实例
  • 对不起,我的意思是目录名 :-) tnx
  • dirname(FILE) 返回 D:\Hosting\5291199\html\sites\Main\wp-content\plugins\exec-php\includes
  • 好的,这就是你的起点。 test.php 在哪个文件夹中?根据我的回答,从您所在的文件夹中,您可以通过将 ../ 附加到 dirname 来上移文件夹。例如。包括 (dirname(FILE) . "/../test/test.php");
  • 返回 D:\\Hosting\\5291199\\html 你在正确的轨道上理查德。 PHP 中没有一个实用程序可以说 gimmefullpath($a_virtual_path_here)。在 asp 中,我们得到了 server.mappath,你可以用它来做 server.mappath("/test/test.asp") 这让你 d:/whatever/whatever/test/test.php
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-17
  • 1970-01-01
  • 1970-01-01
  • 2011-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多