【问题标题】:download gzip file via php cURL通过 php cURL 下载 gzip 文件
【发布时间】:2011-01-19 07:40:59
【问题描述】:

我想下载文件并保存。 我正在使用此代码下载 gzip 文件。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->_params['url']);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
$post = array("image_id"=>  $this->_response_id, "format"=>$this->_response_format);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch);
curl_close($ch);

但是当我打印结果类型时,我看到的是字符串(我得到的是字符串格式的文件)。

如何解决这个问题?

谢谢

【问题讨论】:

  • 一个与我的问题相关的注释:当我打印 ($info = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);) 我看到 image/svg+xml.@ goreSplatter 时,我忘了说你我 2投票给你我为你的评论(我知道你喜欢它:))

标签: php curl gzip


【解决方案1】:

你我认为还需要包括以下选项。

CURLOPT_ENCODING

它处理“Accept-Encoding:”标头的内容。这使得能够对响应进行解码。支持的编码是“identity”、“deflate”和“gzip”。

p.s:开始接受答案或停止提问。也许你也需要知道 this

还可以查看this 链接并尝试使用补丁。

【讨论】:

  • 我尝试了所有这些选项,但结果是一样的。
  • 当我写 thi 时:$info = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); curl_close($ch); echo '
    '."type is :".'
    '.$info;我得到的类型是: image/svg+xml 。我不明白这是什么意思。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-30
  • 2012-07-27
  • 2014-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多