PHP uses file_get_contents to download the image. if there is a variable, you can enter a link.

Source: Internet
Author: User
{Code...} re-write the question. I used the above code to download the image. However, if file_get_contents ($ urlimg) is written in this way, the downloaded image is invalid. But I use echo $ urlimg to output the address, and then manually write the address file_get_contents (& #039; xxx.com & #039 ;)...
(... Code that uses regular expressions to extract and splice links...) $ urlimg = 'http: // xxx.com '; $ img_file = done', $ img_file );

Try again.
I used the above code to download the image.
However, if file_get_contents ($ urlimg) is written in this way, the downloaded image is invalid.
But I use echo $ urlimg to output the address, and then manually write the address file_get_contents ('http: // xxx.com '), but it is normal.
It is also from $ urlimg, but it is OK after you manually write it. They are also plain text variables.
The problem cannot be found.

---- Update

I tried it intermittently for several days. When I first described the problem, I remembered whether there was any encoding problem. Various outputs to see what is stored in the variable. Save the $ urlimg variable content to the txt file. The Link & symbol is written&. However, such output is not displayed on the webpage. After you replace it yourself, there will be no problem.

How can the problem be solved?

Reply content:
(... Code that uses regular expressions to extract and splice links...) $ urlimg = 'http: // xxx.com '; $ img_file = done', $ img_file );

Try again.
I used the above code to download the image.
However, if file_get_contents ($ urlimg) is written in this way, the downloaded image is invalid.
But I use echo $ urlimg to output the address, and then manually write the address file_get_contents ('http: // xxx.com '), but it is normal.
It is also from $ urlimg, but it is OK after you manually write it. They are also plain text variables.
The problem cannot be found.

---- Update

I tried it intermittently for several days. When I first described the problem, I remembered whether there was any encoding problem. Various outputs to see what is stored in the variable. Save the $ urlimg variable content to the txt file. The Link & symbol is written&. However, such output is not displayed on the webpage. After you replace it yourself, there will be no problem.

How can the problem be solved?

Assign values to variables in the buffer zone and check the php ob-related content.
Paste a recently written QR code. refer

// Enable cache ob_start (); $ url = base64_encode ($ value); $ imgPath = "http://pan.baidu.com/share/qrcode? W = 280 & h = 280 & url = "$ url; // png image $ origin = ImageCreateFromPNG ($ imgPath); // Generate Image imagepng ($ origin ); // save variable $ img = ob_get_contents (); $ value = iconv ("UTF-8", "GBK", $ value); // write file $ handle = fopen ($ dir_path. '/'.20.value.'.png', 'w'); fwrite ($ handle, $ img); fclose ($ handle); // disable the buffer and do not output it, here we can see how to adjust ob_end_clean ();

Use curl

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.