Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Runkit_沙盒打开文件_Php - Fatal编程技术网

Php 如何使用Runkit_沙盒打开文件

Php 如何使用Runkit_沙盒打开文件,php,Php,我使用以下代码使用Runkit_Sandbox打开文件: <?php $options = array( 'open_basedir'=>'/var/www/html/test/', 'allow_url_fopen'=>'true', ); $sandbox = new Runkit_Sandbox($options); $sandbox->ini_set('html_errors',true); $sandbox->fopen('/var/www/ht

我使用以下代码使用Runkit_Sandbox打开文件:

<?php
$options = array(
  'open_basedir'=>'/var/www/html/test/',
  'allow_url_fopen'=>'true',
);
$sandbox = new Runkit_Sandbox($options);
$sandbox->ini_set('html_errors',true);

$sandbox->fopen('/var/www/html/test/data.txt', 'r');

?>
我在这里缺少什么?

fopen()
返回一个资源。资源和对象不能在解释器之间交换。基本上,您要做的是打开沙箱中的文件,并要求将文件句柄从沙箱返回到当前上下文中。这是不可能的

您可以使用eval():


我不知道RUNKIT的情况,但是有些事情告诉我你应该把
'open\u basedir'=>'/var/www/html/test',
改为
'open\u basedir'=>'/var/www/html/test/,
然后
('/var/www/html/test/data.txt',r')
试一下,看看它是否能起作用。我更新了这个问题。事实上,我第一次写的脚本就像你在上面的评论一样,但它不起作用。Runkit需要绝对文件路径。确定。我无法测试你的代码。在尝试了PHP.net中的示例代码后,我收到了以下错误
致命错误:在中找不到类“Runkit\u Sandbox”…
很抱歉,我无法提供更多帮助(我尝试了)。(am位于托管服务器上)。
Warning: Runkit_Sandbox::__call(): Unable to translate resource, or object variable to current context. in /var/www/html/test/write1.php on line 10
$sandbox->eval('
  $f = fopen("/var/www/html/test/data.txt", "r");
  // ... rest of the code
');