So my iPhone app sends a shopping cart in a XML file to a URL through POST. Here is the line of code that does that
NSString *pathToSerializedCart = [rootPath stringByAppendingPathComponent:@"serializedCart.plist"];
NSString *shoppingCartString;
NSData *serializedData;
if (![fileManager fileExistsAtPath:pathToSerializedCart])
{
NSLog(@"ERROR:\nCouldnt find serialized cart in documents folder.");
return;
}
serializedData = [NSData dataWithContentsOfFile:pathToSerializedCart];
shoppingCartString = [[NSString alloc] initWithData:serializedData
encoding:NSUTF8StringEncoding];
NSLog(@"%@", shoppingCartString);
[shoppingCartString release];
//==========================================================================
NSData *returnData = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc]
initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);
[returnString release];
Now what Id like to do is put a script on the server in the file welcome.php so that the contents of this XML file are echoed to the browser.
I’ve looked at many examples but they all talk about the situation where the XML file is present in the same directory as the PHP file on the server. I haven’t been able to find examples of PHP code that actually is evoked from an app.
Could someone please point me to the right direction.
Thanks
UPDATE After seeing your full objc, I think the POST value name in question is
userfileand I’ve updated the code below.In PHP, the filename location of your uploaded file will reside in
$_FILES['userfile']['tmp_name']. It is recommended tovar_dump($_FILES)so you can understand how PHP treats the uploaded file.The function
file_get_contents()will read that temporary filename and return its contents as a string, which you can load into DOMDocument, as in the last bit of code below..Recommended reading: PHP docs on the
$_FILESsuperglobal arrayYou’ll need to retrieve your XML data from the
$_POST[]superglobal, and then you can parse it withsimplexml_load_string().Or instead of SimpleXML I usually prefer the more flexible PHP DOMDocument library: