WeChat development, using the following method to save files is not saved

Source: Internet
Author: User
Development, using the following method to save the file is unable to save use the method below the file has been generated, unable to save the file, Cainiao one, hope to help answer.
Function savePic ($ serverId, $ picName ){
$ AccessToken = $ this-> getAccessToken ();
$ TargetName = './upload/'.w.picname.'.jpg ';
$ Ch = curl_init ("http://file.api.weixin.qq.com/cgi-bin/media/get? Access_token = $ accessToken & media_id = $ serverId ");
$ Fp = fopen ($ targetName, 'WB ');
Curl_setopt ($ ch, CURLOPT_FILE, $ fp );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_exec ($ ch );
Curl_close ($ ch );
Fclose ($ fp );
}


Reply to discussion (solution)

What does it mean that files cannot be saved?

What does it mean that files cannot be saved?


The file is created successfully. after the method is executed, the file size is still 0 KB.

Comment out curl_setopt ($ ch, CURLOPT_FILE, $ fp );
$ S = curl_exec ($ ch );
Check the length of $ s

I suspect that Reading failed.

Comment out curl_setopt ($ ch, CURLOPT_FILE, $ fp );
$ S = curl_exec ($ ch );
Check the length of $ s

I suspect that Reading failed.


The read length using strlen is 69416. Is there a problem with the curl I wrote?

Look at this.
Curl_setopt ($ ch, CURLOPT_FILE, $ fp );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
// Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_exec ($ ch );

Look at this.
Curl_setopt ($ ch, CURLOPT_FILE, $ fp );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
// Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
Curl_exec ($ ch );


Okay, thank you,
Related Article

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.