简体   繁体   English

如何使用Runkit_Sandbox打开文件

[英]How to open a file using Runkit_Sandbox

I use the following code to open a file with Runkit_Sandbox: 我使用以下代码通过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');

?>

I already create the data.txt file in '/var/www/html/test/' directory with an appropriate permission. 我已经在具有适当权限的'/ var / www / html / test /'目录中创建了data.txt文件。 However, I still get this error: 但是,我仍然收到此错误:

Warning: Runkit_Sandbox::__call(): Unable to translate resource, or object variable to current context. in /var/www/html/test/write1.php on line 10

What am I missing here? 我在这里想念什么?

fopen() returns a resource. fopen()返回资源。 Resources and objects cannot be exchanged between interpreters. 资源和对象不能在解释器之间交换。 What you basicly do is open the file inside the sandbox, and ask to return the file handle from the sandbox into your current context. 您基本上要做的是打开沙箱中的文件,并要求将文件句柄从沙箱返回到当前上下文中。 This is not possible. 这是不可能的。

You can use eval(): 您可以使用eval():

$sandbox->eval('
  $f = fopen("/var/www/html/test/data.txt", "r");
  // ... rest of the code
');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM