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