PHP uses CURL to download files

Source: Internet
Author: User
PHP uses CURL to upload files. it is very convenient to use curl to upload files. no headers or post strings are generated. use fsockopen to write a bunch of curls: $ file = array ("upimg" = & gt; "@ E:/png.png"); // file path. add @ before, indicating that PHP uses CURL to upload files.
It is very convenient to upload files using curl. no headers or post strings are generated. you need to write a bunch of data using fsockopen.
Curl:
$ File = array ("upimg" => "@ E:/png.png"); // file path. add @ in front to indicate file upload. $ curl = curl_init ("http: // localhost/. 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"; // start with the boundary. Note that by default, two more '-' $ postStr than 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"; $ postStr. = $ uploadFile. "\ r \ n"; $ postStr. = "--". $ boundary. "\ r \ n"; // fwrite ($ fp, "POST/. php HTTP/1.0 \ r \ n "); fwrite ($ fp," Content-T Ype: multipart/form-data; boundary = ". $ boundary. "\ r \ n"); fwrite ($ fp, "Content-length :". strlen ($ postStr ). "\ r \ n"); fwrite ($ fp, $ postStr); while (! Feof ($ fp) {echo fgets ($ fp, 128);} fclose ($ fp); print_r ($ _ FILES );

1 floor pz9042 2011-10-24 I would like to ask, can curl Upload FILES? according to your code, print $ _ FILES at the specified url, there is indeed information,, I couldn't find a file in the so-called temporary folder, and I was unable to upload the file. I hope you can post the main code. your current code is just filled in with information, no uploaded code

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.