[英]PHP getimagesize empty output
<?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 Forbidden in /html/test.php on line 6
--而如果我使用另一张图片,它会显示正确的值
$URL='http://getfavicon.appspot.com/http://google.com?defaulticon=1pxgif';
编辑:我想在论坛中启用外部图像,但我想先检查它们的大小。 那么,我该怎么做才能获得图像的大小,而其服务器正在“阻止我”?
编辑:allow_url_fopen 设置为 ON,是的。
伪造 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;
?>
源代码
看起来你提到的 URL 有问题,你可以试试下面的代码我没有做任何事情只是改变了 URL,
URL = "http://forums.phpfreaks.com/uploads/profile/photo-thumb-68615.jpg";
list($width, $height) = getimagesize($URL);
echo 'width: ' . $width . '<br>height: ' . $height;
将 PHP 内存限制设置为最大 256 Mb 以修复它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.