<?php
$URL="http://cor-forum.de/forum/images/smilies/zombie.png";
list($width, $height) = getimagesize($URL);
echo 'width: '.$width.'<br>
height: '.$height;
?>这将产生以下结果:
width:
height:编辑并得到以下警告:
警告: getimagesize(http://cor-forum.de/forum/images/smilies/zombie.png):打开流失败: HTTP请求失败!HTTP/1.1 403禁止在第6行/html/test.php中使用
-而如果我使用另一张图片,则会显示正确的值,例如
$URL='http://getfavicon.appspot.com/http://google.com?defaulticon=1pxgif';编辑:我想在论坛中加入外部图片,但我想先检查它们的大小。那么,我能做些什么来得到一个图像的大小,它的服务器正在“阻止我”呢?
编辑: allow_url_fopen设置为ON,是的。
发布于 2014-08-10 18:02:27
伪造HTTP referer字段似乎适用于这个字段:
<?php
function getimgsize($url, $referer = '')
{
$headers = array(
'Range: bytes=0-32768'
);
/* Hint: you could extract the referer from the url */
if (!empty($referer)) array_push($headers, 'Referer: '.$referer);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
$image = imagecreatefromstring($data);
$return = array(imagesx($image), imagesy($image));
imagedestroy($image);
return $return;
}
list($width, $heigth) = getimgsize('http://cor-forum.de/forum/images/smilies/zombie.png', 'http://cor-forum.de/forum/');
echo $width.' x '.$heigth;
?>code的来源
发布于 2014-08-10 17:45:34
看起来你对上面提到的URL有问题,你能试试下面的代码吗?我没有做任何事情,只是改变了URL,
URL = "http://forums.phpfreaks.com/uploads/profile/photo-thumb-68615.jpg";
list($width, $height) = getimagesize($URL);
echo 'width: ' . $width . '<br>height: ' . $height;发布于 2018-01-18 11:18:05
将PHP内存限制设置为最大256 Mb以修复它
https://stackoverflow.com/questions/25230949
复制相似问题