简体   繁体   English

PHP getimagesize 空输出

[英]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;
?>

This results in the following output:这导致以下输出:

width:
height:

EDIT and I get the following warning:编辑,我收到以下警告:

Warning: getimagesize( http://cor-forum.de/forum/images/smilies/zombie.png ): failed to open stream: HTTP request failed!警告:getimagesize( http://cor-forum.de/forum/images/smilies/zombie.png ):无法打开流:HTTP 请求失败! HTTP/1.1 403 Forbidden in /html/test.php on line 6 HTTP/1.1 403 Forbidden in /html/test.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';

EDIT: 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"?那么,我该怎么做才能获得图像的大小,而其服务器正在“阻止我”?

EDIT: allow_url_fopen is set to ON, yes.编辑:allow_url_fopen 设置为 ON,是的。

Faking the HTTP referer field seems to work on this one:伪造 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;
?>

Source of code代码

Looks like your having problem with mentioned URL can you try the below code I have not done anything just changed the URL,看起来你提到的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM