PHP getimagesize() not working

本小妞迷上赌 提交于 2019-12-17 13:34:31

问题


<?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! 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';

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.


回答1:


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;
?>

Source of code




回答2:


Looks like your having problem with mentioned URL can you try the below code I have not done anything just changed the URL,

URL = "http://forums.phpfreaks.com/uploads/profile/photo-thumb-68615.jpg";
list($width, $height) = getimagesize($URL);
echo 'width: ' . $width . '<br>height: ' . $height;



回答3:


set PHP memory limit to maximum 256 Mb to fix it



来源:https://stackoverflow.com/questions/25230949/php-getimagesize-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!