WeChat development-php download network image problems, the local test is successful, the files downloaded from the server are only more than 100 bytes

Source: Internet
Author: User
Tags php download
{Code...} both of the above methods can be tested locally, but put on the server, the downloaded images are only more than 100 bytes, and the image cannot be opened. This method is used to obtain images from the server. Is it caused by the related settings in php. ini? Which settings can be modified...
Function geturlimg ($ url, $ filename = "") {if (! CreateDirs (dirname ($ filename) {die ('Folder cannot be created ');} if (! $ Url) die ('no url'); ob_start (); readfile ($ url); $ img = ob_get_contents (); ob_end_clean (); $ size = strlen ($ img); if ($ size) {$ fp2 = @ fopen ($ filename, "a"); fwrite ($ fp2, $ img ); fclose ($ fp2); return $ filename;} else return false;} function getUrlImg3 ($ url, $ filename = "") {if (! CreateDirs (dirname ($ filename) {die ('Folder cannot be created ');} if (! $ Url) die ('no url'); $ ch = curl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_NOBODY, 0 ); // only the body header curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ ch, success, FALSE); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); $ package = curl_exec ($ ch); $ httpinfo = curl_getinfo ($ ch); curl_close ($ ch); $ imageAll = array_merge (array ('header' => $ httpinfo ), arr Ay ('body' => $ package); // The upper half is download, and the lower half is save if ($ package) {$ local_file = fopen ($ filename, 'w '); if (false! ==$ Local_file) {if (false! = Fwrite ($ local_file, $ package) {fclose ($ local_file); return true ;}} return false ;}

The above two methods can be tested locally, but they can be put on the server. The downloaded images only contain more than 100 bytes, and the images cannot be opened. This method is used to obtain images from the server. Is it caused by the related settings in php. ini? Which settings can be modified?

This problem has been disabled because I updated the access_token during local debugging, And the token cached on the server is useless, update the server token.

Reply content:
Function geturlimg ($ url, $ filename = "") {if (! CreateDirs (dirname ($ filename) {die ('Folder cannot be created ');} if (! $ Url) die ('no url'); ob_start (); readfile ($ url); $ img = ob_get_contents (); ob_end_clean (); $ size = strlen ($ img); if ($ size) {$ fp2 = @ fopen ($ filename, "a"); fwrite ($ fp2, $ img ); fclose ($ fp2); return $ filename;} else return false;} function getUrlImg3 ($ url, $ filename = "") {if (! CreateDirs (dirname ($ filename) {die ('Folder cannot be created ');} if (! $ Url) die ('no url'); $ ch = curl_init ($ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_NOBODY, 0 ); // only the body header curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ ch, success, FALSE); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); $ package = curl_exec ($ ch); $ httpinfo = curl_getinfo ($ ch); curl_close ($ ch); $ imageAll = array_merge (array ('header' => $ httpinfo ), arr Ay ('body' => $ package); // The upper half is download, and the lower half is save if ($ package) {$ local_file = fopen ($ filename, 'w '); if (false! ==$ Local_file) {if (false! = Fwrite ($ local_file, $ package) {fclose ($ local_file); return true ;}} return false ;}

The above two methods can be tested locally, but they can be put on the server. The downloaded images only contain more than 100 bytes, and the images cannot be opened. This method is used to obtain images from the server. Is it caused by the related settings in php. ini? Which settings can be modified?

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.