PHP-getimagesize()重定向不起作用 [英] PHP - getimagesize() redirect not working

查看:117
本文介绍了PHP-getimagesize()重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:getimagesize()不适用于某些URL,尤其是正在重定向的URL.

Problem: getimagesize() does not work for some URLs, especially ones that are redirecting.

我用Google搜索并检查了stackoverflow,但无济于事.

I googled around and checked stackoverflow but to no avail.

这是我在本地计算机上看到的内容:

Here's what I see on my local machine:

var_dump(getimagesize('http://gan.doubleclick.net/gan_impression?lid=41000000015155731&pubid=21000000000506299&lsrc=17'));

> Array
(
    [0] => 120
    [1] => 90
    [2] => 2
    [3] => width="120" height="90"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

并在我的服务器上:

var_dump(getimagesize('http://gan.doubleclick.net/gan_impression?lid=41000000015155731&pubid=21000000000506299&lsrc=17'));

> bool(false)

我尝试了其他图像和URL,它们工作正常.正是这个URL给我带来了问题.我还尝试了以下操作(在我的服务器上),并且此可以起作用:

I tried other images and URLs, and they work fine. It's this URL that is giving me a problem. I also tried the following (on my server), and this does work:

echo strlen(file_get_contents('http://gan.doubleclick.net/gan_impression?lid=41000000015155731&pubid=21000000000506299&lsrc=17'));

> 4829 // This number means it works

错误日志没有任何内容,也没有其他提示可以告诉我.我猜这是需要在php.ini中进行更改的

The error log has nothing, and there is no other hints I can tell. I'm guessing it's something that needs to change in the php.ini

推荐答案

如果file_get_contents有效,那么fopen肯定有效

If file_get_contents works then definitely fopen would work

因为您遇到权限问题,所以卷曲将是最佳选择,但是您也可以使用 FastImage . .读取图像标题并获取信息,而不是 必须将整个文件保存在本地

Curl would have been the best option since you are having permission issue but you can also use FastImage .. to read the image headers and get the information instead of having to save the whole file locally

示例

$img = new FastImage("http://gan.doubleclick.net/gan_impression?lid=41000000015155731&pubid=21000000000506299&lsrc=17");
var_dump($img->getSize(),$img->getType());

输出

array (size=2)
  0 => int 120
  1 => int 90
string 'jpeg' (length=4)

简单演示

这篇关于PHP-getimagesize()重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆