PHP uses curl to simulate post upload and receive files, _php tutorial

Source: Internet
Author: User

PHP uses curl to simulate the way post uploads and receives files,


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]
"," 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 readers interested in PHP related content can view this site topic: "PHP Curl Usage Summary", "PHP date and Time usage summary", "PHP Object-oriented Programming tutorial", "PHP String Usage Summary", "php+ MySQL database operation Getting Started tutorial and PHP Common database operation Skills Summary

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • PHP Curl simulates a POST request and submits a multidimensional array of sample code
    • PHP Post data upload instance based on Curl
    • PHP function Sharing curl way to get data, analog login, post data
    • Troubleshoot problems with PHP Curl post
    • PHP Curl analog post submission Data sample
    • PHP Curl Analog POST Request small instance
    • Ways to implement get and post requests using curl in PHP
    • Code for post data to API interface using Curl mode under PHP
    • Three ways to post data in PHP using curl, socket, file_get_contents
    • PHP's Curl Library features crawl web pages, post data, and more
    • PHP Curl analog Get and post function code
    • PHP's curl implements the Get and post code

http://www.bkjia.com/PHPjc/1106116.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106116.html techarticle PHP uses curl to simulate post upload and receive file methods, this article describes the PHP using Curl analog post upload and receive files. Share to everyone for your reference, as follows: ...

  • 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.