$url = "http://baidu.com/img.png"; $path = "img.png"; $fp = fopen($path, 'w+'); $ch = curl_init(); curl_setopt($ch, CURLOPT_ENCODING,'gzip'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_FILE, $fp); // 用于传输的文件流,默认是 STDOUT $output = curl_exec($ch); if ($output === false) { throw new \Exception("文件下载失败:$url"); } else { fclose($fp); curl_close($ch); } 虽然下载成功了,但是打开图片后仅有原图的部分,另一部分显示为灰色。 怎么改进一下?或者是什么原因造成的。
