This article mainly introduces PHP using curl to simulate post upload and receive files, related to PHP using Curl to implement post file transfer skills, the need for friends can refer to the following
This example describes how PHP simulates post upload and receive files using Curl. Share to everyone for your reference, as follows:
Public Function Action_upload () {$this->path_config (); Exit (); $furl = "@d:\develop\jmframeworkwithdemo.rar"; $url = "http://localhost/DemoIndex/curl_pos/"; $this->upload_file_to_cdn ($furl, $url);} Public Function Upload_file_to_cdn ($furl, $url) {//Initialize $ch = Curl_init (); To upload the local file address "@f:/xampp/php/php.ini" upload time, the upload path must be preceded by the @ symbol $post _data = Array ("Upload" and $furl); Print_r ($post _data); Where does curlopt_url mean to submit? Equivalent to the path specified in the form "action"//$url = "http://localhost/DemoIndex/curl_pos/"; Set Variable curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 0);//Whether the execution result is returned, 0 is returned, 1 is not returned curl_setopt ($ch, Curlopt_header, 0);//Parameter setting, Whether the header information is displayed, 1 is displayed, 0 is not displayed//forged page source address, forged form from Baidu submitted curl_setopt ($ch, Curlopt_referer, "http://www.baidu.com"); form data, is the normal form setting value is not 0 curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, curlopt_timeout, 100);//sets the maximum amount of curl execution time-out (//) when using an array to provide post data, the Curl component is presumably intended to be compatible with the @filename of this upload file,// By default the Content_Type is set to Multipart/form-data. Although there is no impact on most Web servers and/or, there are still a few servers that are incompatible. This paper concludes that, in the case of no need to upload files//circumstances, as far as possible to the post submitted data http_build_query, and then sent out, to achieve better compatibility, smaller request packets. curl_setopt ($ch, Curlopt_postfields, $post _data); Execute and obtain results curl_exec ($ch); if (curl_exec ($ch) = = = FALSE) {echo "<br/>", "Curl Error:" Curl_error ($ch); }//Release curl handle Curl_close ($ch); echo "Aaa45";} function Action_curl_pos () {var_dump ($_files); $AA = Move_uploaded_file ($_files["Upload" ["Tmp_name"], "/wamp/tools/1.rar"); if ($AA) {echo "11"; }}
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!