PHP uses curl to upload files

Source: Internet
Author: User
Tags what header
PHP Uploading files using curl
Using Curl to upload the file is very convenient, what Header,post string are not generated, with Fsockopen to write a bunch of
Curl
$file = Array ("upimg" + "@e:/png.png");//file path, preceded by @, indicates file upload. $curl = Curl_init ("http://localhost/a.php"); curl_ Setopt ($curl, curlopt_post,true); curl_setopt ($curl, Curlopt_postfields, $file); curl_exec ($curl);

Fsockopen
$uploadFile = file_get_contents ("E:/png.png"), $boundary   = MD5 (Time ()), $postStr. = "--". $boundary. " \ r \ n ";//The boundary begins, notice that the default is more than two '-' $postStr of the boundary defined by the header. =" Content-disposition:form-data; Name=\ "upimg\"; Filename=\ "e:/png.png\" \ r \ n "; $postStr. =" content-type:image/png\r\n\r\n "; $postStr. = $uploadFile." \ r \ n "; $postStr. ="--". $boundary." \ r \ n ";//Boundary End fwrite ($fp," post/a.php http/1.0\r\n "); Fwrite ($fp," content-type:multipart/form-data; boundary= ". $ Boundary. " \ r \ n "); Fwrite ($fp," Content-length: ". strlen ($POSTSTR)." \r\n\r\n ") fwrite ($fp, $POSTSTR), while (!feof ($fp)) {     echo fgets ($FP, 128);} Fclose ($fp);p rint_r ($_files);

1/F pz9042 2011-10-24

I want to ask, curl can upload files, according to your code, in the specified URL to print $_files, there is information, but, I do not find files in the so-called temporary folder, but also can not upload files, landlord, I hope you post the main code, your current code, just fill in the information, No uploaded code at all

  • Related Article

    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.