Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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 从GuzzleHttp、getContents的乱码数据写入文件(GuzzleHttp\Psr7\Response)_Php_Guzzle - Fatal编程技术网

Php 从GuzzleHttp、getContents的乱码数据写入文件(GuzzleHttp\Psr7\Response)

Php 从GuzzleHttp、getContents的乱码数据写入文件(GuzzleHttp\Psr7\Response),php,guzzle,Php,Guzzle,我一直在尝试的是从数据中获取一个文件,它应该是可读的 下面是一行使用GoogleDriveAPI的代码 $result = $this->service->files->export("ID", 'mimeType', array( 'alt' => 'media')) ->getBody() ->getContents(); $result获取GuzzleHttp\Psr7\Response的对象。这

我一直在尝试的是从数据中获取一个文件,它应该是可读的

下面是一行使用GoogleDriveAPI的代码

$result = $this->service->files->export("ID", 'mimeType', array(
        'alt' => 'media'))
          ->getBody()
          ->getContents();
$result
获取
GuzzleHttp\Psr7\Response
的对象。这最初是一个可读的
Google.doc
文件。但是,
$result
是乱码,我用
var\u dump()
确认了它

有没有人想到将
GuzzleHttp\Psr7\Response
对象转换(或还原)为可读文件? 另外,如果您能给出将恢复的
$result
保存为doc、pdf或任何其他主要格式的想法,我将不胜感激


仅供参考:我使用的是Laravel 5,它具有GuzzleHttp。

您需要用read()替换getContents

这对我很有用:

$file = $service->files->export($request->id, 'application/pdf', array('alt' => 'media' ));
$size = $file->getBody()->getSize();
$content = $file->getBody()->read($size);