PHP file_get_contents cannot display pictures

Source: Internet
Author: User
 
  Array ("header" = "Referer:". $refer)); $context =stream_context_create ($opt); $file _contents = file_get_contents ($url, False, $context); Echo $file _contents; >

I want to forge a referer, and then use file_get_contents to get the picture to show,
But the display is garbled, how to solve?


Reply to discussion (solution)

No problem with the code!
Remove the BOM header from the program file

If you want the entire file to be output as a picture, precede it with a sentence: header ("Content-type:image/png");

You try the method of the second floor!

Plus go, but the same is garbled

Garbled page, cut a picture to see

This is the only way to add a type declaration

This is definitely not your code to produce!
This is a high version of JPEG not PNG
And this format in the lower version of the browser is not open, can only be garbled or a fork


Sorry, my picture URL input is not the same as the question, but the problem is still not resolved

I'm sorry--I'm too quick to read what you said.
It's OK to browse with chrome, thanks.

The header of the picture is added to echo the stream data directly.

If you know each other's picture format you can simply save the data stream each time to generate a picture locally to display it.

You use Notepad to open the picture is like this, with the header Content-type try

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.