日期:2014-05-16 浏览次数:20490 次
$url = 'http://wiki.mbalib.com/w/images/2/22/%E6%B3%9B%E6%88%90%E6%9C%AC%E7%9A%84%E7%89%B9%E5%BE%81.jpg';如果你的 php 版本还没有那么高,可以自己写代码。网上也可以搜索到。
$s = file_get_contents($url);
echo gzdecode($s);
function gzdecode($data) {
$len = strlen($data);
if ($len < 18
------解决方案--------------------
strcmp(substr($data,0,2),"\x1f\x8b")) {
return $data; // Not GZIP format (See RFC 1952)
}
$method = ord(substr($data,2,1)); // Compression method
$flags = ord(substr($data,3,1)); // Flags
if ($flags & 31 != $flags) {
// Reserved bits are set -- NOT ALLOWED by RFC 1952
return data;
}
// NOTE: $mtime may be negative (PHP integer limitations)
$mtime = unpack("V", substr($data,4,4));
$mtime = $mtime[1];
$xfl = substr($data,8,1);
$os = substr($data,8,1);
$headerlen = 10;
$extralen = 0;
$extra = "";
if ($flags & 4) {
// 2-byte length prefixed EXTRA data in header
if ($len - $headerlen - 2 < 8) {
return false; // Invalid format
}
$extralen = unpack("v",substr($data,8,2));
$extralen = $extralen[1];
if ($len - $headerlen - 2 - $extralen < 8) {
return false; // Invalid format
}
$extra = substr($data,10,$extralen);
$headerlen += 2 + $extralen;
}
$filenamelen = 0;
$filename&