0

我不知道为什么,但我很难找到如何做到这一点。我想做的只是发布到同一目录中的另一个 .php 文件,然后在浏览器中显示该页面的内容以及发布的数据。

我正在使用它,但我需要访问一个不在 web 根目录中的 php 文件:

$post_data = http_build_query(array('stratus_code' => $this->stratus_code));
    $options = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $post_data));
    $context = stream_context_create($options);
    $result = file_get_contents('http://stratus.sylentec.com/' . $page, false, $context);
    echo $result;
4

2 回答 2

0

$this->stratus_code 这是一个数组吗?还是一个字符串?

http://php.net/manual/en/function.stream-context-create.php

您没有使用 chr(10) 。将数组中的 chr(13) 推送到 stream_context_create ;

'内容类型:应用程序/x-www-form-urlencoded'

于 2012-07-29T04:40:50.620 回答
-1

您不能通过 http 请求将任何内容直接发布到 PHP 文件中。PHP 文件只是一个源文件,它告诉 PHP 解释器,由Web 服务器调用如何处理传入的请求。

如果您的 PHP 文件位于您的 Web 根目录之外(换句话说,您的 Web 服务器无法执行 PHP 文件),那么您将永远无法构建可以访问您的 PHP 文件的 http 请求。

您要么需要:

  • 将您的 PHP 文件放在您的 Web 服务器将处理的位置(例如,在您的 Web 根目录中)
  • 使用对PHP CLI的系统调用来绕过 Web 服务器。
于 2012-07-29T04:47:19.867 回答