没有javascript的PHP getimagesize()替代品? [英] PHP getimagesize() alternatives without javascript?

查看:115
本文介绍了没有javascript的PHP getimagesize()替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个图像的URL,并且在服务器配置中禁用了URL文件访问,这不是我可以(或想要)更改的东西,是否有一种简单的方法可以使用PHP获取它的高度/宽度?
如果可能,我不想使用javascript。

Say I have the URL of an image, and URL file-access is disabled in the server configuration, and that's not something I can (or want) to change, is there an easy way to get it's height/width using PHP? I'd prefer not to use javascript if possible.

推荐答案

为了检查远程图像,你'不得不以某种方式要求它。您无法确定无法看到的内容的属性。如果为PHP安装禁用远程文件访问,则可能必须将其置于系统级进程,例如wget,cURL或ftp。

In order to examine a remote image, you're going to have to request it somehow. You can't determine properties of something you can't see. If remote file access is disabled for your PHP installation, you might have to farm this out to a system level process, such as wget, cURL, or ftp.

赔率为如果您的主机已禁用远程文件访问,他们可能也禁用了shell访问,但作为示例,您可以执行以下操作:

Odds are if your host has disabled remote file access, they've probably disabled shell access too, but as an example, you could do something like:

exec("wget ".$url);

另一种选择可能是使用内置cURL包,如果通过一些奇怪的配置安装并激活,尽管没有远程文件访问。

Another option might be to use the built-in cURL package, if by some odd configuration it's installed and active despite not having remote file access.

如果你能想出一种从远程服务器下载图像的方法,你可以使用 getimagesize()就可以了。

If you can figure out a way to download the image from the remote server, you can use getimagesize() on it.

这篇关于没有javascript的PHP getimagesize()替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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