From: Aaron A. <li...@fr...> - 2008-04-13 16:58:15
|
Option 2 is what I'm trying to do, but the problem is that when curl sends the file over the command line, when it's processes via PHP the attached file comes over $_FILES. But, added the postdata obviously doesn't allow it to come over that way. Is there any way to use option 2 and transmit the file so it will come over under $_FILES? -- Aaron Bojan Tesanovic wrote: > > On Apr 12, 2008, at 11:37 PM, Aaron Axelsen wrote: > >> I am trying to create the following command with the php curl functions: >> >> curl -F "data=@domain.xml" "http://path/to/api" >> >> The problem i'm having is that i'm creating the xml file with php - >> so the contents are stored in a variable. How can I send the >> contents of that variable via curl? I thought just assigning the xml >> variable to data would work - but it hasn't. >> >> Any suggestions? >> >> -- >> Aaron Axelsen >> li...@fr... >> >> Great hosting, low prices. Modevia Web Services LLC -- >> http://www.modevia.com >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > > > What I can suggest > 1. save the XML to file eg xmldata.xml and use > system('curl -F "data=@xmldata.xml" "http://path/to/api" '); > > 2. or Use PHP CURL functions > > fufunction postData($postFileds,$url){ > $ch = curl_init(); > curl_setopt($ch, CURLOPT_URL, $url); > curl_setopt($ch, CURLOPT_POST ,1); > curl_setopt($ch, CURLOPT_POSTFIELDS ,$postFileds); > curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); > curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN > HTTP HEADERS > curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE > CONTENTS OF THE CALL > $data = curl_exec($ch); > curl_close($ch); > return $data; > } > > $xmlData = 'some xml data'; > $postFileds = 'data='. urlencode($xmlData); > > //call function > postData($postFileds,"http://path/to/api"); > > > > ------- > Bojan > http://www.carster.us/ > > > > > -- Aaron Axelsen li...@fr... Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com |