PHP getimagesize 不带 URL 文件访问

发布于 2024-10-05 16:45:42 字数 425 浏览 1 评论 0原文

我在 PHP 中使用 getimagesize 来获取有关脚本中图像的信息...

$thumb = "http://i.ytimg.com/vi/u6XAPnuFjJc/hqdefault.jpg";
$imageInfo = getimagesize($thumb);

问题是在我的一台服务器上,它返回错误:

getimagesize() [function.getimagesize]:服务器配置中禁用 URL 文件访问

我将无法修复此特定服务器上的此配置问题。我想知道是否有人对我如何解决这个问题有任何想法。是否可以获取图像,将其保存到临时文件,然后根据临时图像使用 getimagesize ?全部完成后,需要删除临时文件。

如果这是可能的,我会怎么做?

I am using getimagesize in PHP to get information about an image in my script...

$thumb = "http://i.ytimg.com/vi/u6XAPnuFjJc/hqdefault.jpg";
$imageInfo = getimagesize($thumb);

The problem is that on one of my servers, it is returning the error:

getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration

I will not be able to fix this configuration issue on this specific server. I'm wondering if anyone has any ideas on how I can work around this issue. Would it be possible to take the image, save it to a temporary file and then use getimagesize based on the temporary image? Once its all done, the temporary file would then need to be deleted.

If this is possible, how would I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海螺姑娘 2024-10-12 16:45:42

由于您能够更改服务器配置,因此请检查 CURL 是否已启用。

如果是,那么您可以使用 CURL 将图像复制到本地并对其运行 getimagesize。

http://php.net/manual/en/book.curl.php

Since you're to able to change server configuration, check if CURL is enabled.

If it is, then you can use CURL to copy the image locally and run getimagesize on it.

http://php.net/manual/en/book.curl.php

为你鎻心 2024-10-12 16:45:42

听起来你有 fopen()< /code> URL 包装已禁用allow_url_fopen = off

您需要使用 cURL 之类的工具来下载它,然后对其运行 list($width, $height) = getimagesize()

Sounds like you have fopen() URL wrappers disabled allow_url_fopen = off.

You will need to use something like cURL to download it, and then run list($width, $height) = getimagesize() on it.

倾城泪 2024-10-12 16:45:42

如果未启用 CURL,您仍然可以使用套接字和 HTTP 请求在本地复制图像 - 您还可以使用它来检查文件大小(Content-Length 标头)以确保您的脚本不会下载大量文件(有人试图通过这样做来 DOS 我的网站 XD)

If CURL is not enabled, you can still copy the image locally using sockets and an HTTP request - you can also use this to check the filesize (Content-Length header) to make sure your script doesn't download massive files (someone tried to DOS my site by doing that XD)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文