[英]PHP function file_get_contents retrieves encoded information - header: “'Content-Type: image/png'”
Hi everyone I am having a bit of a problem related to the php function file_get_contents
. 大家好,我遇到了与php函数
file_get_contents
相关的问题。
I used it many times and no problems but when I am trying to get some information from a particular site the information I get when I echo
the result is pretty much encoded (Example: IHDR
). 我使用了很多次,没有问题,但是当我尝试从特定站点获取一些信息时,我在
echo
显结果时所获得的信息几乎已经被编码了(例如: IHDR
)。
I looked at the header of the site and instead of saying 我看着网站的标题,而不是说
Content-Type: text/html;
it is saying 这是说
Content-Type: image/png
How do I decode that so I can get the source code (html) of the site? 我该如何解码以获取网站的源代码(html)? The web-site when I go to it in a browser, it looks like a regular web-site: text, images nothing out of ordinary.
当我在浏览器中访问该网站时,它看起来像一个常规网站:文本,图像没有任何异常。
When I look at the source code nothing out of ordinary there either. 当我查看源代码时,也没有什么异常之处。 But when I do a
file_get_contents
I do not get the source code like I used to get on other websites. 但是,当我执行
file_get_contents
,不会像以前在其他网站上那样获得源代码。
Any ideas? 有任何想法吗?
Note: I had the same problem in the past it was encoded in GZIP and I was able to find a function to decode it but with Content-Type: image/png
I do not know how to proceed. 注意:过去我也遇到过同样的问题,它是用GZIP编码的,我能够找到一个函数对其进行解码,但是使用
Content-Type: image/png
我不知道如何进行。
Why not, create a basic test script to the output the returned image, tho I suspect its an image saying: 为什么不创建一个基本的测试脚本来输出返回的图像,我怀疑它的图像说:
Stop scrapping my site!!!
停止抓取我的网站!!! Yada Yada
亚达亚达
header('Content-Type: image/png');
echo file_get_contents('http://example.com');
The Content-Type
header tells you which content-type the requested file has, in your case it is a PNG image ( image/png
). Content-Type
标头告诉您请求的文件具有哪种内容类型,在您的情况下为PNG图片( image/png
)。
You find a description of many content-types (written in a so called mime-type specification) online, this is a nice list: fileformat.info MIME types . 您可以在线找到许多内容类型的描述(以所谓的mime-type规范编写),这是一个不错的列表: fileformat.info MIME types 。
As you might can imagine, it's not possible to display an image in text-form (at least not before converting it to ascii art) so you will not have much luck this time. 可以想象,不可能以文本形式显示图像(至少在将其转换为ascii art之前没有显示),因此这次您将没有太多运气。
Check the URI if it is really the one you wanted to obtain. 检查URI是否确实是您要获取的URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.