Here I am writing code using curl
The local code is as follows:
| The code is as follows: |
Copy code |
<? Php Header ('content-type: text/html; charset = utf8 '); $ Curl = curl_init (); $ Data = array ('IMG '=>' @ '. dirname (_ FILE _).'/img/login.gif '); Curl_setopt ($ curl, CURLOPT_URL, "http://www.demo.com/uploadimg.php "); Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true ); Curl_setopt ($ curl, CURLOPT_POST, true ); Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data ); $ Result = curl_exec ($ curl ); Curl_close ($ curl ); Echo json_decode ($ result ); ?> |
Remote server receiver code:
| The code is as follows: |
Copy code |
<? Php If ($ _ FILES) { $ Filename = $ _ FILES ['IMG '] ['name']; $ Tmpname = $ _ FILES ['IMG '] ['tmp _ name']; If (move_uploaded_file ($ tmpname, dirname (_ FILE _). '/img/'. $ filename )) { Echo json_encode ('upload successful '); } Else { $ Data = json_encode ($ _ FILES ); Echo $ data; } } ?> |
For example, curl is also used, but ftp is used.
| The code is as follows: |
Copy code |
<? Php $ Localfile = "php_homepage.txt "; $ Fp = fopen ($ localfile, "r "); $ Arr_ip = gethostbyname (www.111cn.net ); Echo $ arr_ip; $ Ftp = "ftp: //". $ arr_ip. "/public_html/". $ localfile; $ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_VERBOSE, 1 ); Curl_setopt ($ ch, CURLOPT_USERPWD ,'***:****'); Curl_setopt ($ ch, CURLOPT_URL, $ ftp ); Curl_setopt ($ ch, CURLOPT_PUT, 1 ); Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); Curl_setopt ($ ch, CURLOPT_INFILE, $ fp ); Curl_setopt ($ ch, CURLOPT_INFILESIZE, filesize ($ localfile )); $ Http_result = curl_exec ($ ch ); $ Error = curl_error ($ ch ); Echo $ error. "<br> "; $ Http_code = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); curl_close ($ ch ); Fclose ($ fp ); ?> |