PHP getimagesize()无法正常工作
<?php
$URL="http://cor-forum.de/forum/images/smilies/zombie.png";
list($width, $height) = getimagesize($URL);
echo 'width: '.$width.'<br>
height: '.$height;
?>
这将导致以下输出:
width:
height:
编辑,我收到以下警告:
EDIT and I get the following warning:
警告: getimagesize( http://cor-forum.de/forum/images/smilies/zombie .png ): 无法打开流:HTTP请求失败! HTTP/1.1 403禁止输入 /home/webpages/lima-city/regnum-forum/html/DATEIEN/scheisstest.php在 第6行
Warning: getimagesize(http://cor-forum.de/forum/images/smilies/zombie.png): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/webpages/lima-city/regnum-forum/html/DATEIEN/scheisstest.php on line 6
-如果我使用其他图片,则它会显示正确的值
--whereas it displays the right values if I use another picture like
$URL='http://getfavicon.appspot.com/http://google.com?defaulticon=1pxgif';
我想在论坛中包含外部图像,但我想先检查其大小. 那么,我该怎么做才能获得服务器正在阻止我"的图像的大小?
I'd like to enable the inclusion of external images in a forum, but I want to check their size first. So, what can I do to get the size of an image, whose server is "blocking me"?
allow_url_fopen设置为ON,是的.
allow_url_fopen is set to ON, yes.
在此引用站点上似乎无法使用HTTP参考字段:
Faking the HTTP referer field seems to work on this one:
<?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;
?>