Jfergy Posted December 3, 2013 Share Posted December 3, 2013 I have the following code which works just fine sending the $xml. However when i try to add a file to be sent with the xml as well i get an error. I tried using a postData array but then got an array to string error. The way i have it now works but it only sends the xml not the file. Any ideas on how I can send the @file with the postfields? Any help is appreciated $header = array('Content-Type: multipart/form-data'); $xml['xml'] = '<UploadPhoto>'; $xml['xml'] .= '<ID>12345</ID>'; $xml['xml'] .= '<PhotoID>myphoto</PhotoID>'; $xml['xml'] .= '<Filename>myphoto.jpg</Filename>'; $xml['xml'] .= '<Instructions>Need cheeks less rosy</Instructions>'; $xml['xml'] .= '</UploadPhoto>'; $postData = array( 'file' => '@/myphoto.jpg', 'xml' => $xml ); } $connection = curl_init(); curl_setopt($connection, CURLOPT_URL, "http://www.myurl.com/api"); curl_setopt($connection, CURLOPT_HTTPHEADER, $header); curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($connection, CURLOPT_POST, 1); curl_setopt($connection, CURLOPT_POSTFIELDS, $xml); curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1); set_time_limit(108000); $output = curl_exec($connection); curl_close($connection); print_r($output); Quote Link to comment Share on other sites More sharing options...
dalecosp Posted December 3, 2013 Share Posted December 3, 2013 What does $output say, then? Who controls "myurl.com/api" ... and if it's you, does it produce output ... log files ... error messages? What does the API look like? Pretty hard to guess with not much to look at besides a short script and a description of the issue. It's a two-part system, and there's at *least* a 50-percent chance it's the handler, I'd think. No insult intended ... but these seem to be important questions that you've not told us about yet. :-) Quote Link to comment Share on other sites More sharing options...
Jfergy Posted December 3, 2013 Author Share Posted December 3, 2013 The API is controlled by another party and output is not given other than to say the file is not sent. In sending the XML its posting properly by itself. The real issue for me is combining the xml post data with an actual file as well. Im sorry I dont have much more than that as the API im working with is not great. However, its good enough to know I did not send it a file when I just send the xml. Output right now simply states no file uploaded with order. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted December 3, 2013 Share Posted December 3, 2013 Well, you'll probably want to talk to the other party, then. Do they have docs somewhere? Tech support? Quote Link to comment Share on other sites More sharing options...
Jfergy Posted December 3, 2013 Author Share Posted December 3, 2013 Yes, but my question is not how they are responding its how I send an image file in an array with xml via curl. This is a question on my side not theirs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.