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