gpt4 book ai didi

php - getimagesize 和 https

转载 作者:可可西里 更新时间:2023-10-31 23:33:56 31 4
gpt4 key购买 nike

我正在从 facebook 检索 facebook 相册图像。我使用 php 函数 getimagesize 计算图像大小。当 url 处于 http 模式时,此函数工作正常。当 facebook 使用 https 返回图像 url 时,getimagesize 给出错误.我如何使用 getimage size 计算具有 https 扩展名的图像的图像大小

最佳答案

您的 PHP 实例中没有安装 OpenSSL 扩展,因此 https:// 包装器不可用。

From the manual :

Note: HTTPS is only supported when the openssl extension is enabled.

And :

To use PHP's OpenSSL support you must also compile PHP --with-openssl[=DIR] .

您需要使用 OpenSSL 扩展重新编译 PHP。

或者,按照其他人的建议,您可以将 https:// 替换为 http://,这对于 Facebook 图片应该同样有效 - 事实上,它可能会更快,并且肯定会更有效地利用带宽。

我会这样做:

$url = 'https://facebook.com/path/to/image.jpg';
$url = trim($url); // Get rid of any accidental whitespace
$parsed = parse_url($url); // analyse the URL
if (isset($parsed['scheme']) && strtolower($parsed['scheme']) == 'https') {
// If it is https, change it to http
$url = 'http://'.substr($url,8);
}

关于此的另一点是,将 $url 直接传递给 getimagesize() 可能不是您想要做的。您对图像所做的唯一事情不太可能是获取它的大小,您可能会在您的页面上显示它或以其他方式操纵它,如果是这种情况,您最终将不止一次下载它。

您可能应该将它下载到一个临时目录,然后处理它的本地副本。

关于php - getimagesize 和 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8518403/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com