【问题标题】:file_get_contents(): stream does not support seekingfile_get_contents():流不支持查找
【发布时间】:2014-03-17 20:53:52
【问题描述】:

我收到此错误:

`file_get_contents(): stream does not support seeking

我不知道如何修复它。没有资源 ID 或任何东西。

这是我的代码:

$postData = array('name' => $name, 'description' => $description, 'date_begin' => $start, 'date_end' => $end);

  $stream = array(
            'http' => array(
                'header'  =>   "Content-type: application/x-www-form-urlencoded\r\n"
                                . "Authorization: Basic Y3Nub2VrOnNuMDNr\r\n",
                'method'  => 'POST',
                'content' => http_build_query($postData)
            )
        );

    return stream_context_create($stream);

并且在流返回的文件中。它的函数getApiContext

$responseJson = json_decode(file_get_contents('http://10.0.0.89/api/v1/projects', false, BaseController::getApiContext(), true));

然后我得到了这个烦人的错误。我知道 cUrl,但我必须使用流。

【问题讨论】:

  • 您是否在特定的代码行上得到了这个?对应的是哪一行?

标签: php


【解决方案1】:

为什么你的file_get_contents 偏移参数上有true?也许你打算把它放在json_decode 如果是这样,试试这个:

$responseJson = json_decode(file_get_contents('http://10.0.0.89/api/v1/projects', false, BaseController::getApiContext()),true);

【讨论】:

    【解决方案2】:

    您似乎将第四个参数传递给 file_get_contents,远程流不支持此参数(根据文档:http://no1.php.net/manual/en/function.file-get-contents.php

    更改对 file_get_contents 的调用以将其排除(或将其传递给 json_decode,如果这是您的意图)。

    $responseJson = json_decode(file_get_contents('http://10.0.0.89/api/v1/projects', false, BaseController::getApiContext()));
    

    【讨论】:

      猜你喜欢
      • 2019-03-27
      • 2014-06-30
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-26
      • 1970-01-01
      相关资源
      最近更新 更多