This example describes how PHP uses curl to simulate post upload and file receiving. Share it with you for your reference, details: publicfunctionAction_Upload () {$ this-path_config (); exit (); $ furl @ d: developJMFrameworkWithDemo.rar; $ urllocalhostDemoIndexcurl_pos
This example describes how PHP uses curl to simulate post upload and file receiving. Share with you for your reference, specific: public function Action_Upload () {$ this-path_config (); exit (); $ furl = "@ d: \ develop \ JMFrameworkWithDemo.rar "; $ url = "http: // localhost/DemoIndex/curl_pos /"
This example describes how PHP uses curl to simulate post upload and file receiving. We will share this with you for your reference. The details are 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 (); // address of the local file to be uploaded "@ F:/xampp/php. ini "before the upload path, you must have the @ symbol $ post_data = array (" upload "=> $ furl); // print_r ($ post_data ); // CURLOPT_URL indicates where to submit it? Equivalent to the path specified by "action" in the form // $ url =" http://localhost/DemoIndex/curl_pos/ "; // Set the 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 settings, whether to display the header information, 1 is displayed, 0 is not displayed // forge the webpage source address, forge a form from Baidu and submit curl_setopt ($ ch, CURLOPT_REFERER ," http://www.baidu.com "); // Form data, which is a regular form setting value that is not 0 curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_TIMEOUT, 100 ); // set the maximum timeout value for curl execution. // when the array is used to provide post data, the CURL component is probably used to be compatible with the file uploading method such as @ filename, // content_type is set to multipart/form-data by default. Although it does not affect most web servers, a small number of servers are not compatible. The conclusion in this article is that, without the need to upload a file //, we try to perform http_build_query on the data submitted by post and then send it out to achieve better compatibility, smaller request packets. Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data); // execute and obtain the result curl_exec ($ ch); if (curl_exec ($ ch) === FALSE) {echo"
"," 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 ";}}