1. when a user clicks the QR code download link on the website, the server obtains the generated QR code and downloads it to the same code test machine on the user's computer. the image cannot be opened online, the code is as follows {code ...} it is basically determined that the environment is different. Download the image code. when you click download QR code link on the website, the server obtains the generated QR code and downloads it to the user's computer.
There is no problem with the same code testing machine. the image cannot be opened online,
The code is as follows:
Public function download () {$ url = "https://mp.weixin.qq.com/cgi-bin/showqrcode? Ticket = xxxxxxxxxx "; $ tmp = file_get_contents ($ url); $ file_name =" weixin.jpg "; // enter the file tag Header (" Content-type: application/octet-stream "); Header (" Accept-Ranges: bytes "); Header (" Accept-Length :". strlen ($ tmp); Header ("Content-Disposition: attachment; filename = ". $ file_name); // echo $ tmp; exit ();}
It is basically determined that the environment is different.
What are the requirements for server configuration or software installation?
In the same code, the downloaded images can be opened on the testing machine. The Online machines cannot be opened.
--------------------- Separation line ------------------------
After detection, it is found that other classes referenced online have blank row output (which may be the bom header or the php code closure?> It is too difficult to find the output header, the image cannot be opened, and there are too many files.
Add the following code to solve the problem.
// Clear the previous output to ensure the image is complete. Ob_start (); ob_end_flush (); ob_end_clean ();
Reply content:
1. when a user clicks the download QR code link of the website, the server obtains the generated QR code and downloads it to the user's computer.
There is no problem with the same code testing machine. the image cannot be opened online,
The code is as follows:
Public function download () {$ url = "https://mp.weixin.qq.com/cgi-bin/showqrcode? Ticket = xxxxxxxxxx "; $ tmp = file_get_contents ($ url); $ file_name =" weixin.jpg "; // enter the file tag Header (" Content-type: application/octet-stream "); Header (" Accept-Ranges: bytes "); Header (" Accept-Length :". strlen ($ tmp); Header ("Content-Disposition: attachment; filename = ". $ file_name); // echo $ tmp; exit ();}
It is basically determined that the environment is different.
What are the requirements for server configuration or software installation?
In the same code, the downloaded images can be opened on the testing machine. The Online machines cannot be opened.
--------------------- Separation line ------------------------
After detection, it is found that other classes referenced online have blank row output (which may be the bom header or the php code closure?> It is too difficult to find the output header, the image cannot be opened, and there are too many files.
Add the following code to solve the problem.
// Clear the previous output to ensure the image is complete. Ob_start (); ob_end_flush (); ob_end_clean ();
I have encountered this problem. I think the error isfile_get_contents
. Your url is https,file_get_contents
The result will be stuck. try curl instead.file_get_contents
The problem should be solved.
(There are two ssl Settings in curl that allow the program to access https normally. This should be known as this)
Header ("Accept-Length:". strlen ($ tmp); do not define this try
strlen
When0
It is considered that the string has reached the end, and the middle of the image may appear0
So I only obtained part of the image data. of course, I cannot open it.
For example
$ Hex = '000000' // The result is 3332310033323131313131313131313131313131313131313131313131313131313131313131313131, that is, all values after 0 are invalid.