php - use curl to pass file from one server to another -
i have web server receives posted data form, 1 part of can attached image. want use curl send information along second server. works fine requests not include image, when image included in original post get:
curl error 26: failed creating formpost data
i know indicates curl unable find file, having trouble determining why not. here code
if ($_post) { $postdata = array(); //copy in post fields posted here foreach ($_post $key => $value) { $postdata[$key] = $value; } //copy in files have been included foreach ($_files $key => $value) { if ($value["tmp_name"]) { //if null, no file uploaded $fn = "existing_image.jpg";//(use existing debugging //in reality, use tmp image) $postdata[$key] = "@" . realpath($fn) . ";type=" . $value["type"]; $testmsg .= "added file $key value of '" . $postdata[$key] . "'(" . file_exists($fn) . ")\n"; } } $testmsg .= "postdata:\n" . print_r($postdata, true); $options[curlopt_post] = true; $options[curlopt_postfields] = $postdata; }
and here output:
added file photo value of '@/var/www/wordpress/somedirectory/php/existing_image.jpg;type=image/jpeg'(1) postdata: array ( [key1] => 4 [key2] => blah blah text [key3] => etc [keyimage] => @/var/www/wordpress/somedirectory/php/existing_image.jpg;type=image/jpeg )
the file indeed exists - why curl giving me error? appreciate can give...
edit: not have same problem when servers 1 , 2 same server (i.e. when set web page on second server receives posted data , executes same curl code send info along itself). means something, evidently overlooking something...
i'm not sure perhaps php
or curl
version doesn't support setting content type way. try remove type=
part code , let curl decide content type:
$postdata[$key] = "@" . realpath($fn);
you try setting curlopt_verbose
flag true , see if more descriptive error message.
Comments
Post a Comment