开发者

PHP getimagesize() alternatives without 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?开发者_如何学C I'd prefer not to use javascript if possible.


umm, so you're going to pull the image over the network into your PHP application "find" the size, and then presumably emit an HTML img take with the size? seems kind of funky to me.


This doesn't really make much sense since if you can view the image on a web page, the image should be directly accessible via the URL. Why, in other words, would you have a url to an image that can't be accessed via url?

Regardless, you can use any number of http/url libraries to set a user-agent in the header of the request. Essentially, you trick the server into believing that a browser is accessing the file, rather than an anonymous service.

Here is a list of browser user agents you can use for this purpose.


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.

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);

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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜