Stream_get_content 第二次不工作?

Roo*_*oud 4 php streaming

我第一次使用 stream_get_content 。一切似乎都很好,直到我第二次尝试从流中读取内容。

如果我传递给 stream_get_content 的值是重复的,则返回空值!?

但如果我的价值不是重复一切都很好!!!!

public function makeAvatar($value)
{
    $file_result = "data:image/gif;base64,";
    $file_result .= base64_encode(stream_get_contents($value));
    return $file_result;
}
Run Code Online (Sandbox Code Playgroud)

小智 5

您可以使用rewind()将指针重置为流的开头。