How does PHP implement WeChat image upload to the server?

Source: Internet
Author: User
This article mainly introduces the PHP implementation of the image upload to the server method, involving PHP based on the curl operation of the image file implementation skills, the need for friends can refer to the next

The example of this article describes how PHP implements the image upload to the server. Share to everyone for your reference, as follows:

 $pic _img=trim ($postObj->picurl); if ($type = = "image") {$pic _url=save_file_   To_sever ($pic _img, $fromUsername);}  Getrootpath () {$sRealPath = Realpath ('./');  $sSelfPath = $_server[' php_self ');  $sSelfPath = substr ($sSelfPath, 0, Strrpos ($sSelfPath, '/')); Return substr ($sRealPath, 0, strlen ($sRealPath)-strlen ($sSelfPath));}  function Save_file_to_sever ($url, $fromid) {$gen =getrootpath ();  $time =time (); $newfname = $gen. " /weixin/wx_huodong/xiawucha/". $fromid. $time.  JPG ';  $ch =curl_init ();  $timeout = 5;  curl_setopt ($ch, Curlopt_url, $url);  curl_setopt ($ch, curlopt_returntransfer,1);  curl_setopt ($ch, Curlopt_connecttimeout, $timeout);  $img =curl_exec ($ch);  Curl_close ($ch);  $size =strlen ($IMG);  File size $fp 2= @fopen ($newfname, ' a ');  Fwrite ($fp 2, $img);  Fclose ($fp 2); Return "www.xxx.com/weixin/wx_huodong/xiawucha/". $fromid. $time. JPG ';} 

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.