我正在尝试获取图像的内容类型和内容长度。在localhost /浏览器和LAMP / LEMP上的响应是不同的。如何获得与localhost /浏览器相同的真实响应?
这是我尝试过的an image URL。
在本地主机上的响应:
HTTP Code: 200
Type: image/png
Length: 1017
在LAMP / LEMP服务器上的响应:
HTTP Code: 200
Type: image/jpeg
Length: 4232
这是我的代码
$imageUrl = 'https://3.bp.blogspot.com/DXIeeda-C_xS6xqUiVnUnx6vMOkNmahpW0TypbGdx8Cy3q2L5ds9YUyfMroVQo4ERxw8MQyqY0A'; //type = png
$imageInfo = getInfo($imageUrl);
print_r($imageInfo);
function getInfo($requestUrl) {
$handle = curl_init($requestUrl);
curl_setopt_array($handle, array(
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36', CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_NOBODY => 1,
CURLOPT_HEADER => 1
));
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$type = curl_getinfo($handle, CURLINFO_CONTENT_TYPE);
$length = curl_getinfo($handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($handle);
return 'HTTP Code: ' . $code . "\n" . 'Type: ' . $type . "\n" . 'Length: ' . $length;
}
我希望标头响应的输出为
内容类型:image / png
但是实际输出是
内容类型:图片/ jpeg