首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP getimagesize空输出

PHP getimagesize空输出
EN

Stack Overflow用户
提问于 2014-08-10 16:56:09
回答 3查看 21.2K关注 0票数 4
代码语言:javascript
复制
<?php
$URL="http://cor-forum.de/forum/images/smilies/zombie.png";
list($width, $height) = getimagesize($URL);

echo 'width: '.$width.'<br>
height: '.$height;
?>

这将产生以下结果:

代码语言:javascript
复制
width:
height:

编辑并得到以下警告:

警告: getimagesize(http://cor-forum.de/forum/images/smilies/zombie.png):打开流失败: HTTP请求失败!HTTP/1.1 403禁止在第6行/html/test.php中使用

-而如果我使用另一张图片,则会显示正确的值,例如

代码语言:javascript
复制
$URL='http://getfavicon.appspot.com/http://google.com?defaulticon=1pxgif';

编辑:我想在论坛中加入外部图片,但我想先检查它们的大小。那么,我能做些什么来得到一个图像的大小,它的服务器正在“阻止我”呢?

编辑: allow_url_fopen设置为ON,是的。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-08-10 18:02:27

伪造HTTP referer字段似乎适用于这个字段:

代码语言:javascript
复制
<?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的来源

票数 7
EN

Stack Overflow用户

发布于 2014-08-10 17:45:34

看起来你对上面提到的URL有问题,你能试试下面的代码吗?我没有做任何事情,只是改变了URL,

代码语言:javascript
复制
URL = "http://forums.phpfreaks.com/uploads/profile/photo-thumb-68615.jpg";
list($width, $height) = getimagesize($URL);
echo 'width: ' . $width . '<br>height: ' . $height;
票数 -1
EN

Stack Overflow用户

发布于 2018-01-18 11:18:05

将PHP内存限制设置为最大256 Mb以修复它

票数 -3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25230949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档