PHP getimagesize() alternatives without javascript?

坚强是说给别人听的谎言 提交于 2019-12-25 03:44:43

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/2145021/php-getimagesize-alternatives-without-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!