PHP uses curl to simulate post uploads and receive files _php tips

Source: Internet
Author: User
Tags curl rar

The example in this article describes how PHP uses curl to simulate post uploads and receive files. Share to everyone for your reference, specific 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);
    The Public Function Upload_file_to_cdn ($furl, $url) {//Initialize $ch = Curl_init ();
    To upload the local file address "@f:/xampp/php/php.ini" upload, the upload path must precede the @ symbol $post _data = Array ("Upload" => $furl);
    Print_r ($post _data); Curlopt_url refers to where to submit?
    Equivalent to the path specified by "Action" in the form//$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 to display head information, 1 for display, 0 for not showing//forgery of Web page source address, forged form submitted from Baidu 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)//Set the maximum Curl execution timeout///when using arrays to provide post data, the Curl component is probably for compatibility @filenameThis type of upload file,//default Content_Type set to Multipart/form-data. Although it has no impact on most Web servers, there are a few servers that are not compatible.
    The conclusion of this article is that, when there is no need to upload the file//case, try to http_build_query the post submitted data, and then send out, can 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";

 }
}

More interested in PHP related content readers can view the site topics: "Php Curl Usage Summary", "PHP date and Time usage summary", "PHP object-oriented Program Design Primer", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.