Using PHP to dynamically create XML file
Posted: Wed Apr 18, 2007 6:21 am
feyd | Please use
but the "source.xml" needs to be the dynamically created file which is produced using the following request:
Then, I have my cURL function.
So, I just need to get the results from the XML request, and stick it in a new XML file which needs to be assigned to the $source variable, in order to upload it.
Hope this makes sense, I'm not great at explaining things
Michael.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi
I am working on a file that uploads an XML file to a server, but the XML file needs to be dynamically generated from the results of an XML request to an API. So, rather than directly setting the source as a specific file I need to use the results from a request to make the XML file, then ftp it to the server.
My code is as follows:Code: Select all
$source = "source.xml";
$destination = "destination/newfilename.xml";
require_once("xml_feed_creator.php");
$xmlFeed = new xmlFeedCreator();
$xmlFeed->CreateXmlFeed($source, $destination);Code: Select all
function makeRequest($api,$user,$check,$type,$params){
$str ="XML_REQUEST=";
$str.="<request>";
$str.="<authorise><email>".$user."</email><checkcode>".$check."</checkcode></authorise>";
$str.="<type>".$type."</type>";
$str.="<parameters>".$params."</parameters>";
$str.="</request>";
return cURL($api,$str);
}Code: Select all
function cURL($link,$poststring){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $link);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $poststring);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
$response = trim(curl_exec ($ch));
return $response;
}Hope this makes sense, I'm not great at explaining things
Michael.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]