Recently to upload files via post, online vibe has curl post submission and fsockopen, where curl is the simplest, so from the simplest. It is simple to post one variable to another page, "$data = Array (' a ' = ' = ' b '); $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_ Setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_post, True); curl_setopt ($ch, Curlopt_postfields, $ Data), $ret = Curl_exec ($ch); Curl_close ($ch); This option Curlopt_returntransfer: If set to TRUE/1, Curl_ exec does not automatically output the content of the requested page to the screen, $ret to request the content of the page, if set to false/0, then curl_exec will automatically output the content of the request page to the screen, if the request is successful $ret content is 1 or true. The following is the code to upload local files, if you need to upload remote files, then down to local, and then delete (if there are other ways students have to tell): $url = "; $file = ' 1.jpg '; $field [' uploadfile '] = ' @ '. $file; (UploadFile is the name name of the receiving end) $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer , 1); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $field); $ret = Curl_exec ($ch); Curl_close ( $CH);-------------------------------------------------------------------------------------This is the way to Fsockopen: $ Uploadinfo = Array (' Host ' => ', ' port ' = ' + ', ' url ' = '/upload.php '); $fp = Fsockopen ($uploadInfo [' Host '], $uploadInfo [' Port '], $errno, $ERRSTR); $file = ' 1.jpg '; $content = file_get_contents ($file); $boundary = MD5 (time ()); $out. = "--". $boundary. " \ r \ n "; $out. = "Content-disposition:form-data; Name=\ "Uploadfile\"; Filename=\ "". $file. " \ "\ r \ n"; $out. = "content-type:image/jpg\r\n\r\n"; $out. = $content. " \ r \ n "; $out. = "--". $boundary. " \ r \ n "; Fwrite ($fp, "POST". $uploadInfo [' url ']. " Http/1.1\r\n "); Fwrite ($FP, "host:". $uploadInfo [' Host ']. " \ r \ n "); Fwrite ($fp, "content-type:multipart/form-data; boundary=". $boundary. " \ r \ n "); Fwrite ($FP, "Content-length:". strlen ($out). " \r\n\r\n "); Fwrite ($fp, $out); while (!feof ($fp)) {$ret. = fgets ($fp, 1024); } Fclose ($FP); $ret = Trim (Strstr ($ret, "\r\n\r\n")); Preg_match ('/http:.*/', $ret, $match); return $match [0];
Application of curl and Fsockopen in PHP