简体   繁体   中英

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 .

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

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? 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.

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.

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

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 .

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.

Check the URI if it is really the one you wanted to obtain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM